Skip to content

Commit

Permalink
feat: normalize type usage of @fxjs/orm.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardo2016 committed Nov 27, 2022
1 parent 2775413 commit 6f030a3
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/Typo/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export namespace FibApp {
}

// keep compatible with definition in '@fxjs/orm'
export interface AppSpecialDateProperty extends FxOrmNS.ModelPropertyDefinition {
export interface AppSpecialDateProperty extends FxOrmModel.ModelPropertyDefinition {
type: 'date'
time?: true
}
Expand Down
6 changes: 3 additions & 3 deletions src/orm_plugins/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FxOrmNS } from '@fxjs/orm';
import type { FxOrmNS, FxOrmModel } from '@fxjs/orm';
import type { FibApp } from '../Typo/app';

import util = require('util')
Expand Down Expand Up @@ -32,7 +32,7 @@ export default function (ormInstance: FibApp.FibAppORM, opts: FxOrmNS.ModelOptio

const orm_definition_hash: {[model_name: string]: {
name: string
properties: Record<string, FxOrmNS.ModelPropertyDefinition>
properties: Record<string, FxOrmModel.ModelPropertyDefinition>
opts: FibApp.FibAppOrmModelDefOptions
}} = {};

Expand All @@ -44,7 +44,7 @@ export default function (ormInstance: FibApp.FibAppORM, opts: FxOrmNS.ModelOptio
'viewServices',
'no_graphql',
]
function beforeDefine (name: string, properties: Record<string, FxOrmNS.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) {
function beforeDefine (name: string, properties: Record<string, FxOrmModel.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) {
opts.timestamp = true

orm_definition_hash[name] = { name, properties, opts }
Expand Down
4 changes: 2 additions & 2 deletions src/orm_plugins/assoc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { FxOrmNS } from "@fxjs/orm";
import { FxOrmNS, FxOrmModel } from "@fxjs/orm";

export default function (
orm: FxOrmNS.ORM,
plugin_opts: {
}
): FxOrmNS.Plugin {
function beforeDefine (name: string, properties: Record<string, FxOrmNS.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) {
function beforeDefine (name: string, properties: Record<string, FxOrmModel.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) {
if ((opts.extension || opts.__for_extension) && !properties.id) {
opts.__webx_use_uuid = true;
}
Expand Down
12 changes: 6 additions & 6 deletions src/orm_plugins/timestamp.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import util = require('util')
import ORM = require('@fxjs/orm')
import { FxOrmNS, FxOrmModel } from '@fxjs/orm';
import { FxOrmNS, FxOrmModel, FxOrmProperty } from '@fxjs/orm';
const Helpers = ORM.Helpers;

interface PluginOptions__Timestamp {
createdPropertyName?: string | false
createdProperty?: FxOrmNS.OrigDetailedModelProperty,
createdProperty?: FxOrmProperty.NormalizedProperty,
updatedPropertyName?: string | false
updatedProperty?: FxOrmNS.OrigDetailedModelProperty,
updatedProperty?: FxOrmProperty.NormalizedProperty,
expiredPropertyName?: string | false
expiredProperty?: FxOrmNS.OrigDetailedModelProperty,
type?: FxOrmNS.OrigDetailedModelProperty
expiredProperty?: FxOrmProperty.NormalizedProperty,
type?: FxOrmProperty.NormalizedProperty
now?: { (): Date }
expire?: { (): Date }
}
Expand All @@ -27,7 +27,7 @@ const defaults_opts: PluginOptions__Timestamp = {
export default function (orm: FxOrmNS.ORM, plugin_opts: PluginOptions__Timestamp = {}) {
plugin_opts = util.extend({}, defaults_opts, plugin_opts)

function beforeDefine (name: string, properties: Record<string, FxOrmNS.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) {
function beforeDefine (name: string, properties: Record<string, FxOrmModel.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) {
if (!opts.timestamp) return;

if (typeof opts.timestamp == 'object')
Expand Down
4 changes: 2 additions & 2 deletions src/orm_plugins/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid = require('uuid')
import ORM = require('@fxjs/orm')
import { FxOrmNS } from '@fxjs/orm';
import { FxOrmNS, FxOrmModel } from '@fxjs/orm';
const Helpers = ORM.Helpers;
const { prependHook } = Helpers;

Expand All @@ -12,7 +12,7 @@ export default function (
): FxOrmNS.Plugin {
let { enable: use_uuid = false } = plugin_opts || {};

function beforeDefine (name: string, properties: Record<string, FxOrmNS.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) {
function beforeDefine (name: string, properties: Record<string, FxOrmModel.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) {
use_uuid = use_uuid || opts.__webx_use_uuid

if (!use_uuid)
Expand Down
2 changes: 1 addition & 1 deletion typings/Typo/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export declare namespace FibApp {
acl: FibAppACL.ACLDefinition;
oacl: FibAppACL.OACLDefinition;
}
interface AppSpecialDateProperty extends FxOrmNS.ModelPropertyDefinition {
interface AppSpecialDateProperty extends FxOrmModel.ModelPropertyDefinition {
type: 'date';
time?: true;
}
Expand Down
4 changes: 2 additions & 2 deletions typings/orm_plugins/app.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { FxOrmNS } from '@fxjs/orm';
import type { FxOrmNS, FxOrmModel } from '@fxjs/orm';
import type { FibApp } from '../Typo/app';
/**
* @description first initial plugin before all other plugins
*/
export default function (ormInstance: FibApp.FibAppORM, opts: FxOrmNS.ModelOptions): {
beforeDefine: (name: string, properties: Record<string, FxOrmNS.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) => void;
beforeDefine: (name: string, properties: Record<string, FxOrmModel.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) => void;
define: (m: FibApp.FibAppORMModel) => FibApp.FibAppORMModel;
};
12 changes: 6 additions & 6 deletions typings/orm_plugins/timestamp.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { FxOrmNS, FxOrmModel } from '@fxjs/orm';
import { FxOrmNS, FxOrmModel, FxOrmProperty } from '@fxjs/orm';
interface PluginOptions__Timestamp {
createdPropertyName?: string | false;
createdProperty?: FxOrmNS.OrigDetailedModelProperty;
createdProperty?: FxOrmProperty.NormalizedProperty;
updatedPropertyName?: string | false;
updatedProperty?: FxOrmNS.OrigDetailedModelProperty;
updatedProperty?: FxOrmProperty.NormalizedProperty;
expiredPropertyName?: string | false;
expiredProperty?: FxOrmNS.OrigDetailedModelProperty;
type?: FxOrmNS.OrigDetailedModelProperty;
expiredProperty?: FxOrmProperty.NormalizedProperty;
type?: FxOrmProperty.NormalizedProperty;
now?: {
(): Date;
};
Expand All @@ -15,7 +15,7 @@ interface PluginOptions__Timestamp {
};
}
export default function (orm: FxOrmNS.ORM, plugin_opts?: PluginOptions__Timestamp): {
beforeDefine: (name: string, properties: Record<string, FxOrmNS.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) => void;
beforeDefine: (name: string, properties: Record<string, FxOrmModel.ModelPropertyDefinition>, opts: FxOrmNS.ModelOptions) => void;
define(model: FxOrmModel.Model): void;
};
export {};

0 comments on commit 6f030a3

Please sign in to comment.