@yongdall/scene 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -62,7 +62,7 @@ var Scene_default = createModel("scene", {
62
62
  label: "Database"
63
63
  }),
64
64
  type: createField("string", {
65
- nullable: true,
65
+ nullable: false,
66
66
  label: "Type"
67
67
  }),
68
68
  tables: createField(SceneTable, {
@@ -77,4 +77,4 @@ var Scene_default = createModel("scene", {
77
77
 
78
78
  //#endregion
79
79
  export { Scene_default as t };
80
- //# sourceMappingURL=Scene-B9LbsSn9.mjs.map
80
+ //# sourceMappingURL=Scene-B_dHIwLD.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Scene-B9LbsSn9.mjs","names":[],"sources":["../../plugins/scene/models/Scene.mjs"],"sourcesContent":["import { createField, createModel, uuid } from '@yongdall/model';\n\nconst SceneField = createModel('scene.field', {\n\tsceneId: createField('uuid', { nullable: false, label: 'ID', primary: 1, layout: {hidden: true} }),\n\tmodel: createField('string', {label: 'model', primary: 2}),\n\n\tcolumn: createField('string', { label: 'Table Field'}),\n\n\tfield: createField('string', { label: 'Field', primary: 3}),\n\tfixedValue: createField('json', { label: '固定值'}),\n\n\tno: createField('i32'),\n\n\t// TODO: 类型、样式、渲染\n});\n\nconst SceneTable = createModel('scene.table', {\n\tsceneId: createField('uuid', { nullable: false, label: 'ID', primary: 1, layout: {hidden: true} }),\n\tmodel: createField('string', {label: 'Model', primary: 2}),\n\t\n\ttable: createField('string', {label: 'Table'}),\n\tno: createField('i32'),\n\tfields: createField(SceneField, { array: true, constraints: {sceneId: {field: 'sceneId'}, model: {field: 'model'}, no: {noField: true}}, label: 'Fields' }),\n});\n\nexport default createModel('scene', {\n\tid: createField('uuid', { nullable: false, default: uuid, label: 'ID', primary: 1, layout: {hidden: true} }),\n\n\tlabel: createField('string', { nullable: false, default: '', label: 'Label' }),\n\n\tdbId: createField('string', { nullable: false, default: '', label: 'Database' }),\n\ttype: createField('string', { nullable: true, label: 'Type' }),\n\ttables: createField(SceneTable, { array: true, constraints: {sceneId: {field: 'id'}, no: {noField: true}}, label: 'tables' }),\n});\n"],"mappings":";;;AAEA,MAAM,aAAa,YAAY,eAAe;CAC7C,SAAS,YAAY,QAAQ;EAAE,UAAU;EAAO,OAAO;EAAM,SAAS;EAAG,QAAQ,EAAC,QAAQ,MAAK;EAAE,CAAC;CAClG,OAAO,YAAY,UAAU;EAAC,OAAO;EAAS,SAAS;EAAE,CAAC;CAE1D,QAAQ,YAAY,UAAU,EAAE,OAAO,eAAc,CAAC;CAEtD,OAAO,YAAY,UAAU;EAAE,OAAO;EAAS,SAAS;EAAE,CAAC;CAC3D,YAAY,YAAY,QAAQ,EAAE,OAAO,OAAM,CAAC;CAEhD,IAAI,YAAY,MAAM;CAGtB,CAAC;AAEF,MAAM,aAAa,YAAY,eAAe;CAC7C,SAAS,YAAY,QAAQ;EAAE,UAAU;EAAO,OAAO;EAAM,SAAS;EAAG,QAAQ,EAAC,QAAQ,MAAK;EAAE,CAAC;CAClG,OAAO,YAAY,UAAU;EAAC,OAAO;EAAS,SAAS;EAAE,CAAC;CAE1D,OAAO,YAAY,UAAU,EAAC,OAAO,SAAQ,CAAC;CAC9C,IAAI,YAAY,MAAM;CACtB,QAAQ,YAAY,YAAY;EAAE,OAAO;EAAM,aAAa;GAAC,SAAS,EAAC,OAAO,WAAU;GAAE,OAAO,EAAC,OAAO,SAAQ;GAAE,IAAI,EAAC,SAAS,MAAK;GAAC;EAAE,OAAO;EAAU,CAAC;CAC3J,CAAC;AAEF,oBAAe,YAAY,SAAS;CACnC,IAAI,YAAY,QAAQ;EAAE,UAAU;EAAO,SAAS;EAAM,OAAO;EAAM,SAAS;EAAG,QAAQ,EAAC,QAAQ,MAAK;EAAE,CAAC;CAE5G,OAAO,YAAY,UAAU;EAAE,UAAU;EAAO,SAAS;EAAI,OAAO;EAAS,CAAC;CAE9E,MAAM,YAAY,UAAU;EAAE,UAAU;EAAO,SAAS;EAAI,OAAO;EAAY,CAAC;CAChF,MAAM,YAAY,UAAU;EAAE,UAAU;EAAM,OAAO;EAAQ,CAAC;CAC9D,QAAQ,YAAY,YAAY;EAAE,OAAO;EAAM,aAAa;GAAC,SAAS,EAAC,OAAO,MAAK;GAAE,IAAI,EAAC,SAAS,MAAK;GAAC;EAAE,OAAO;EAAU,CAAC;CAC7H,CAAC"}
1
+ {"version":3,"file":"Scene-B_dHIwLD.mjs","names":[],"sources":["../../plugins/scene/models/Scene.mjs"],"sourcesContent":["import { createField, createModel, uuid } from '@yongdall/model';\n\nconst SceneField = createModel('scene.field', {\n\tsceneId: createField('uuid', { nullable: false, label: 'ID', primary: 1, layout: {hidden: true} }),\n\tmodel: createField('string', {label: 'model', primary: 2}),\n\n\tcolumn: createField('string', { label: 'Table Field'}),\n\n\tfield: createField('string', { label: 'Field', primary: 3}),\n\tfixedValue: createField('json', { label: '固定值'}),\n\n\tno: createField('i32'),\n\n\t// TODO: 类型、样式、渲染\n});\n\nconst SceneTable = createModel('scene.table', {\n\tsceneId: createField('uuid', { nullable: false, label: 'ID', primary: 1, layout: {hidden: true} }),\n\tmodel: createField('string', {label: 'Model', primary: 2}),\n\t\n\ttable: createField('string', {label: 'Table'}),\n\tno: createField('i32'),\n\tfields: createField(SceneField, { array: true, constraints: {sceneId: {field: 'sceneId'}, model: {field: 'model'}, no: {noField: true}}, label: 'Fields' }),\n});\n\nexport default createModel('scene', {\n\tid: createField('uuid', { nullable: false, default: uuid, label: 'ID', primary: 1, layout: {hidden: true} }),\n\n\tlabel: createField('string', { nullable: false, default: '', label: 'Label' }),\n\n\tdbId: createField('string', { nullable: false, default: '', label: 'Database' }),\n\ttype: createField('string', { nullable: false, label: 'Type' }),\n\ttables: createField(SceneTable, { array: true, constraints: {sceneId: {field: 'id'}, no: {noField: true}}, label: 'tables' }),\n});\n"],"mappings":";;;AAEA,MAAM,aAAa,YAAY,eAAe;CAC7C,SAAS,YAAY,QAAQ;EAAE,UAAU;E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AC,SAAS,MAAK;GAAC;EAAE,OAAO;EAAU,CAAC;CAC7H,CAAC"}
package/index.d.mts CHANGED
@@ -1,25 +1,25 @@
1
- import * as imodel0 from "imodel";
1
+ import * as imodel1 from "imodel";
2
2
  import * as _yongdall_model0 from "@yongdall/model";
3
3
  import { Fields } from "@yongdall/model";
4
4
 
5
5
  //#region plugins/scene/models/Scene.d.mts
6
6
  declare const _default: _yongdall_model0.ModelTable<{
7
- id: imodel0.FieldDefine<"uuid", false, false>;
8
- label: imodel0.FieldDefine<"string", false, false>;
9
- dbId: imodel0.FieldDefine<"string", false, false>;
10
- type: imodel0.FieldDefine<"string", false, true>;
11
- tables: imodel0.FieldDefine<_yongdall_model0.ModelTable<{
12
- sceneId: imodel0.FieldDefine<"uuid", false, false>;
13
- model: imodel0.FieldDefine<"string", false, false>;
14
- table: imodel0.FieldDefine<"string", false, false>;
15
- no: imodel0.FieldDefine<"i32", false, false>;
16
- fields: imodel0.FieldDefine<_yongdall_model0.ModelTable<{
17
- sceneId: imodel0.FieldDefine<"uuid", false, false>;
18
- model: imodel0.FieldDefine<"string", false, false>;
19
- column: imodel0.FieldDefine<"string", false, false>;
20
- field: imodel0.FieldDefine<"string", false, false>;
21
- fixedValue: imodel0.FieldDefine<"json", false, false>;
22
- no: imodel0.FieldDefine<"i32", false, false>;
7
+ id: imodel1.FieldDefine<"uuid", false, false>;
8
+ label: imodel1.FieldDefine<"string", false, false>;
9
+ dbId: imodel1.FieldDefine<"string", false, false>;
10
+ type: imodel1.FieldDefine<"string", false, false>;
11
+ tables: imodel1.FieldDefine<_yongdall_model0.ModelTable<{
12
+ sceneId: imodel1.FieldDefine<"uuid", false, false>;
13
+ model: imodel1.FieldDefine<"string", false, false>;
14
+ table: imodel1.FieldDefine<"string", false, false>;
15
+ no: imodel1.FieldDefine<"i32", false, false>;
16
+ fields: imodel1.FieldDefine<_yongdall_model0.ModelTable<{
17
+ sceneId: imodel1.FieldDefine<"uuid", false, false>;
18
+ model: imodel1.FieldDefine<"string", false, false>;
19
+ column: imodel1.FieldDefine<"string", false, false>;
20
+ field: imodel1.FieldDefine<"string", false, false>;
21
+ fixedValue: imodel1.FieldDefine<"json", false, false>;
22
+ no: imodel1.FieldDefine<"i32", false, false>;
23
23
  }, "scene.field">, true, false>;
24
24
  }, "scene.table">, true, false>;
25
25
  }, "scene">;
@@ -30,6 +30,6 @@ declare const _default: _yongdall_model0.ModelTable<{
30
30
  * @param {string} id
31
31
  * @param {string} table
32
32
  */
33
- declare function loadSceneTable(id: string, table: string): Promise<imodel0.TableDefine<Fields<imodel0.MainFieldType>, string> | undefined>;
33
+ declare function loadSceneTable(id: string, table: string): Promise<imodel1.TableDefine<Fields<imodel1.MainFieldType>, string> | undefined>;
34
34
  //#endregion
35
35
  export { _default as Scene, loadSceneTable };
package/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as Scene_default } from "./Scene-B9LbsSn9.mjs";
2
- import { t as loadSceneTable } from "./loadScene-DAFl6Nul.mjs";
1
+ import { t as Scene_default } from "./Scene-B_dHIwLD.mjs";
2
+ import { t as loadSceneTable } from "./loadScene-Bv4NEas2.mjs";
3
3
 
4
4
  export { Scene_default as Scene, loadSceneTable };
@@ -1,11 +1,13 @@
1
- import { t as Scene_default } from "./Scene-B9LbsSn9.mjs";
1
+ import { t as Scene_default } from "./Scene-B_dHIwLD.mjs";
2
2
  import { Query, Scene } from "@yongdall/model";
3
3
  import { useDatabase } from "@yongdall/connection";
4
4
  import { hooks } from "@yongdall/core";
5
+ import { loadPluginProfiles } from "@yongdall/plugins";
6
+ import { LazyPromise } from "@yongdall/common";
5
7
 
6
8
  //#region plugins/scene/loadScene.mjs
7
- /** @import { Fields } from '@yongdall/model' */
8
- /** @import {SceneType} from './types.mjs' */
9
+ /** @import { Fields, TableValue } from '@yongdall/model' */
10
+ /** @import { SceneType } from './types.mjs' */
9
11
  /**
10
12
  *
11
13
  * @param {Fields} fields
@@ -64,25 +66,42 @@ function toScene({ models, ...define }) {
64
66
  tables
65
67
  };
66
68
  }
67
- /** @type {Record<string, SceneType>} */
69
+ /** @deprecated @type {Record<string, SceneType>} */
68
70
  let scenes = Object.create(null);
69
71
  hooks.listen(() => {
70
72
  scenes = Object.assign(Object.create(null), Object.entries([...hooks.get("scenes").entriesObject()].map(([plugin, k, v]) => [`${plugin}:${k}`, toScene(v)])));
71
73
  }, -1e6);
74
+ const scenePromise = LazyPromise.try(async function() {
75
+ const scenes = await Array.fromAsync(loadPluginProfiles("scene", function* (v, plugin) {
76
+ yield* v ? Object.entries(v).map(([k, v]) => [`${plugin}:${k}`, v]) : [];
77
+ }));
78
+ return Object.fromEntries(scenes);
79
+ });
80
+ /**
81
+ *
82
+ * @param {string} type
83
+ */
84
+ async function findScene(type) {
85
+ const allScenes = await scenePromise;
86
+ if (Object.hasOwn(allScenes, type)) return allScenes[type];
87
+ return Object.hasOwn(allScenes, type) ? allScenes[type] : scenes[type];
88
+ }
72
89
  /**
73
90
  *
74
91
  * @param {string} id
75
92
  * @param {string} table
76
93
  */
77
94
  async function loadSceneTable(id, table) {
78
- /** @type {SceneModel} */
95
+ /** @type {TableValue<SceneModel>} */
79
96
  const sceneDefine = await useDatabase().first(new Query(Scene_default).primary(id));
80
97
  if (!sceneDefine) return;
81
- const sceneModel = scenes[sceneDefine.type].models[table];
98
+ const type = await findScene(sceneDefine.type);
99
+ if (!type) return;
100
+ const sceneModel = type.models[table];
82
101
  if (!sceneModel || typeof sceneModel.table !== "string") return;
83
102
  return new Scene(new Map(sceneDefine.tables.map((t) => [t.table, t]))).table(sceneModel);
84
103
  }
85
104
 
86
105
  //#endregion
87
106
  export { loadSceneTable as t };
88
- //# sourceMappingURL=loadScene-DAFl6Nul.mjs.map
107
+ //# sourceMappingURL=loadScene-Bv4NEas2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadScene-Bv4NEas2.mjs","names":["SceneModel"],"sources":["../../plugins/scene/loadScene.mjs"],"sourcesContent":["/** @import { Fields, TableValue } from '@yongdall/model' */\n/** @import { SceneType } from './types.mjs' */\nimport { useDatabase } from '@yongdall/connection';\nimport { hooks } from '@yongdall/core';\nimport { Query, Scene } from '@yongdall/model';\nimport { loadPluginProfiles } from '@yongdall/plugins';\nimport SceneModel from './models/Scene.mjs';\nimport { LazyPromise } from '@yongdall/common';\n\n/**\n *\n * @param {Fields} fields\n * @returns {Record<string, SceneType.Field>}\n */\nfunction toColumns(fields) {\n\t/** @type {Record<string, SceneType.Field>} */\n\tconst columns = Object.create(null);\n\tfor (const [k, v] of Object.entries(fields)) {\n\t\tconst {type, array, nullable, primary} = v;\n\t\tif (!type) { continue; }\n\t\tconst column = v.column || k;\n\t\tif (typeof type === 'string') {\n\t\t\tcolumns[column] = {type, array: array ? 1 : 0, nullable, primary};\n\t\t\tcontinue;\n\t\t}\n\t\tif (!type.table) {\n\t\t\tcolumns[column] = {type: 'object', array: array ? 1 : 0, nullable, primary: 0};\n\t\t\tcontinue;\n\t\t}\n\t}\n\treturn columns;\n}\n\n/**\n * \n * @param {SceneType.Define} define \n * @returns {SceneType}\n */\nfunction toScene({models, ...define}) {\n\tconst tables = Object.create(null);\n\tconst list = Object.values(models);\n\tfor (let model = list.pop(); model; model = list.pop()) {\n\t\tconst table = model.table;\n\t\tif (typeof table !== 'string') { continue; }\n\t\tif (table in tables) { continue; }\n\t\tconst fields = toColumns(model.fields)\n\t\ttables[table] = {fields};\n\t\tfor (const {type} of Object.values(model.fields)) {\n\t\t\tif (!type) { continue; }\n\t\t\tif (typeof type === 'string') { continue; }\n\t\t\tlist.push(type);\n\t\t}\n\t}\n\n\treturn {\n\t\t...define,\n\t\tmodels: Object.assign(Object.create(null), models),\n\t\ttables,\n\t}\n}\n/** @deprecated @type {Record<string, SceneType>} */\nexport let scenes = Object.create(null);\nhooks.listen(() => {\n\tscenes = Object.assign(\n\t\tObject.create(null),\n\t\tObject.entries([...hooks.get('scenes').entriesObject()]\n\t\t\t.map(([plugin, k, v]) => [`${plugin}:${k}`, toScene(v)])),\n\t);\n}, -1000000);\n\nconst scenePromise = LazyPromise.try(async function () {\n\tconst scenes = await Array.fromAsync(loadPluginProfiles('scene', function *(/** @type {Record<string, SceneType>}*/v, plugin) {\n\t\tyield* v ? Object.entries(v).map(([k, v]) => /** @type {[string, SceneType]} */([`${plugin}:${k}`, v])) : [];\n\t}));\n\treturn Object.fromEntries(scenes);\n});\n/**\n * \n * @param {string} id \n */\nexport default async function loadScene(id) {\n\t/** @type {TableValue<SceneModel>} */\n\tconst sceneDefine = await useDatabase().first(new Query(SceneModel).primary(id));\n\t// TODO: 缓存 sceneDefine\n\tif (!sceneDefine) { return; }\n\tconst scene = new Scene(new Map(sceneDefine.tables.map(t => [t.table, t])));\n\treturn scene\n}\n/**\n * \n * @param {string} type \n */\nasync function findScene(type) {\n\tconst allScenes = await scenePromise;\n\tif (Object.hasOwn(allScenes, type)) { return allScenes[type]; }\n\treturn Object.hasOwn(allScenes, type) ? allScenes[type] : scenes[type];\n}\n/**\n * \n * @param {string} id \n * @param {string} table \n */\nexport async function loadSceneTable(id, table) {\n\t/** @type {TableValue<SceneModel>} */\n\tconst sceneDefine = await useDatabase().first(new Query(SceneModel).primary(id));\n\t// TODO: 缓存 sceneDefine\n\tif (!sceneDefine) { return; }\n\tconst type = await findScene(sceneDefine.type);\n\tif (!type) { return; }\n\tconst sceneModel = type.models[table];\n\tif (!sceneModel || typeof sceneModel.table !== 'string') { return }\n\tconst scene = new Scene(new Map(sceneDefine.tables.map(t => [t.table, t])));\n\t// @ts-ignore\n\treturn scene.table(sceneModel);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAS,UAAU,QAAQ;;CAE1B,MAAM,UAAU,OAAO,OAAO,KAAK;AACnC,MAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,OAAO,EAAE;EAC5C,MAAM,EAAC,MAAM,OAAO,UAAU,YAAW;AACzC,MAAI,CAAC,KAAQ;EACb,MAAM,SAAS,EAAE,UAAU;AAC3B,MAAI,OAAO,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AAG,OAA0C,CAAC,GAAG,OAAO,GAAG,KAAK,EAAE,CAAE,GAAG,EAAE;GAC3G,CAAC;AACH,QAAO,OAAO,YAAY,OAAO;EAChC;;;;;AAiBF,eAAe,UAAU,MAAM;CAC9B,MAAM,YAAY,MAAM;AACxB,KAAI,OAAO,OAAO,WAAW,KAAK,CAAI,QAAO,UAAU;AACvD,QAAO,OAAO,OAAO,WAAW,KAAK,GAAG,UAAU,QAAQ,OAAO;;;;;;;AAOlE,eAAsB,eAAe,IAAI,OAAO;;CAE/C,MAAM,cAAc,MAAM,aAAa,CAAC,MAAM,IAAI,MAAMA,cAAW,CAAC,QAAQ,GAAG,CAAC;AAEhF,KAAI,CAAC,YAAe;CACpB,MAAM,OAAO,MAAM,UAAU,YAAY,KAAK;AAC9C,KAAI,CAAC,KAAQ;CACb,MAAM,aAAa,KAAK,OAAO;AAC/B,KAAI,CAAC,cAAc,OAAO,WAAW,UAAU,SAAY;AAG3D,QAFc,IAAI,MAAM,IAAI,IAAI,YAAY,OAAO,KAAI,MAAK,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAE9D,MAAM,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yongdall/scene",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "type": "module",
@@ -8,9 +8,11 @@
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "dependencies": {
11
+ "@yongdall/common": "^0.5.0",
11
12
  "@yongdall/connection": "^0.5.0",
13
+ "@yongdall/core": "^0.5.0",
12
14
  "@yongdall/model": "^0.5.0",
13
- "@yongdall/core": "^0.5.0"
15
+ "@yongdall/plugins": "^0.5.0"
14
16
  },
15
17
  "devDependencies": {
16
18
  "@yongdall/migrate": "^0.5.0"
@@ -1,4 +1,4 @@
1
- import { t as Scene_default } from "../Scene-B9LbsSn9.mjs";
1
+ import { t as Scene_default } from "../Scene-B_dHIwLD.mjs";
2
2
 
3
3
  //#region plugins/scene/yongdall/migration.mjs
4
4
  /** @import { Profile } from '@yongdall/migrate' */
@@ -1,5 +1,5 @@
1
- import { t as Scene_default } from "../Scene-B9LbsSn9.mjs";
2
- import { t as loadSceneTable } from "../loadScene-DAFl6Nul.mjs";
1
+ import { t as Scene_default } from "../Scene-B_dHIwLD.mjs";
2
+ import { t as loadSceneTable } from "../loadScene-Bv4NEas2.mjs";
3
3
 
4
4
  //#region plugins/scene/yongdall/model.mjs
5
5
  /** @import { ModelProfile } from '@yongdall/core' */
@@ -1 +0,0 @@
1
- {"version":3,"file":"loadScene-DAFl6Nul.mjs","names":["SceneModel"],"sources":["../../plugins/scene/loadScene.mjs"],"sourcesContent":["/** @import { Fields } from '@yongdall/model' */\n/** @import {SceneType} from './types.mjs' */\nimport SceneModel from './models/Scene.mjs';\nimport { useDatabase } from '@yongdall/connection';\nimport { hooks } from '@yongdall/core';\nimport { Query, Scene } from '@yongdall/model';\n\n/**\n *\n * @param {Fields} fields\n * @returns {Record<string, SceneType.Field>}\n */\nfunction toColumns(fields) {\n\t/** @type {Record<string, SceneType.Field>} */\n\tconst columns = Object.create(null);\n\tfor (const [k, v] of Object.entries(fields)) {\n\t\tconst {type, array, nullable, primary} = v;\n\t\tif (!type) { continue; }\n\t\tconst column = v.column || k;\n\t\tif (typeof type === 'string') {\n\t\t\tcolumns[column] = {type, array: array ? 1 : 0, nullable, primary};\n\t\t\tcontinue;\n\t\t}\n\t\tif (!type.table) {\n\t\t\tcolumns[column] = {type: 'object', array: array ? 1 : 0, nullable, primary: 0};\n\t\t\tcontinue;\n\t\t}\n\t}\n\treturn columns;\n}\n\n/**\n * \n * @param {SceneType.Define} define \n * @returns {SceneType}\n */\nfunction toScene({models, ...define}) {\n\tconst tables = Object.create(null);\n\tconst list = Object.values(models);\n\tfor (let model = list.pop(); model; model = list.pop()) {\n\t\tconst table = model.table;\n\t\tif (typeof table !== 'string') { continue; }\n\t\tif (table in tables) { continue; }\n\t\tconst fields = toColumns(model.fields)\n\t\ttables[table] = {fields};\n\t\tfor (const {type} of Object.values(model.fields)) {\n\t\t\tif (!type) { continue; }\n\t\t\tif (typeof type === 'string') { continue; }\n\t\t\tlist.push(type);\n\t\t}\n\t}\n\n\treturn {\n\t\t...define,\n\t\tmodels: Object.assign(Object.create(null), models),\n\t\ttables,\n\t}\n}\n/** @type {Record<string, SceneType>} */\nexport let scenes = Object.create(null);\nhooks.listen(() => {\n\tscenes = Object.assign(\n\t\tObject.create(null),\n\t\tObject.entries([...hooks.get('scenes').entriesObject()]\n\t\t\t.map(([plugin, k, v]) => [`${plugin}:${k}`, toScene(v)])),\n\t);\n}, -1000000);\n\n/**\n * \n * @param {string} id \n */\nexport default async function loadScene(id) {\n\t/** @type {SceneModel} */\n\tconst sceneDefine = await useDatabase().first(new Query(SceneModel).primary(id));\n\t// TODO: 缓存 sceneDefine\n\tif (!sceneDefine) { return; }\n\tconst scene = new Scene(new Map(sceneDefine.tables.map(t => [t.table, t])));\n\treturn scene\n}\n\n/**\n * \n * @param {string} id \n * @param {string} table \n */\nexport async function loadSceneTable(id, table) {\n\t/** @type {SceneModel} */\n\tconst sceneDefine = await useDatabase().first(new Query(SceneModel).primary(id));\n\t// TODO: 缓存 sceneDefine\n\tif (!sceneDefine) { return; }\n\tconst type = scenes[sceneDefine.type];\n\tconst sceneModel = type.models[table];\n\tif (!sceneModel || typeof sceneModel.table !== 'string') { return }\n\tconst scene = new Scene(new Map(sceneDefine.tables.map(t => [t.table, t])));\n\t// @ts-ignore\n\treturn scene.table(sceneModel);\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAS,UAAU,QAAQ;;CAE1B,MAAM,UAAU,OAAO,OAAO,KAAK;AACnC,MAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,OAAO,EAAE;EAC5C,MAAM,EAAC,MAAM,OAAO,UAAU,YAAW;AACzC,MAAI,CAAC,KAAQ;EACb,MAAM,SAAS,EAAE,UAAU;AAC3B,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