@yongdall/scene 0.1.0

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.
@@ -0,0 +1,16 @@
1
+ import { n as Scene_default, t as loadSceneTable } from "./loadScene-C7txwTmV.mjs";
2
+
3
+ //#region plugins/scene/hooks.yongdall.mjs
4
+ /** @import { Hooks } from '@yongdall/core' */
5
+ const models = { scene: Scene_default };
6
+ /** @type {Hooks.Define['migrationModels']} */
7
+ const migrationModels = [Scene_default];
8
+ /** @type {Hooks.Define['modelLoaders']} */
9
+ const modelLoaders = { async scene([sceneId, table, ...other]) {
10
+ if (!table || other.length) return null;
11
+ return await loadSceneTable(sceneId, table);
12
+ } };
13
+
14
+ //#endregion
15
+ export { migrationModels, modelLoaders, models };
16
+ //# sourceMappingURL=hooks.yongdall.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.yongdall.mjs","names":["Scene"],"sources":["../../plugins/scene/hooks.yongdall.mjs"],"sourcesContent":["import { loadSceneTable } from './loadScene.mjs';\nimport Scene from './models/Scene.mjs';\n/** @import { Hooks } from '@yongdall/core' */\n\nexport const models = {\n\tscene: Scene,\n};\n\n/** @type {Hooks.Define['migrationModels']} */\nexport const migrationModels = [\n\tScene\n]\n\n/** @type {Hooks.Define['modelLoaders']} */\nexport const modelLoaders = {\n\t/** @param {string[]} collection */\n\tasync scene([sceneId, table, ...other]) {\n\t\tif (!table || other.length) { return null }\n\t\treturn await loadSceneTable(sceneId, table);\n\t}\n}\n"],"mappings":";;;;AAIA,MAAa,SAAS,EACrB,OAAOA,eACP;;AAGD,MAAa,kBAAkB,CAC9BA,cACA;;AAGD,MAAa,eAAe,EAE3B,MAAM,MAAM,CAAC,SAAS,OAAO,GAAG,QAAQ;AACvC,KAAI,CAAC,SAAS,MAAM,OAAU,QAAO;AACrC,QAAO,MAAM,eAAe,SAAS,MAAM;GAE5C"}
package/index.d.mts ADDED
@@ -0,0 +1,35 @@
1
+ import * as imodel0 from "imodel";
2
+ import * as _yongdall_model0 from "@yongdall/model";
3
+ import { Fields } from "@yongdall/model";
4
+
5
+ //#region plugins/scene/models/Scene.d.mts
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>;
23
+ }, "scene.field">, true, false>;
24
+ }, "scene.table">, true, false>;
25
+ }, "scene">;
26
+ //#endregion
27
+ //#region plugins/scene/loadScene.d.mts
28
+ /**
29
+ *
30
+ * @param {string} id
31
+ * @param {string} table
32
+ */
33
+ declare function loadSceneTable(id: string, table: string): Promise<imodel0.TableDefine<Fields<imodel0.MainFieldType>, string> | undefined>;
34
+ //#endregion
35
+ export { _default as Scene, loadSceneTable };
package/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { n as Scene_default, t as loadSceneTable } from "./loadScene-C7txwTmV.mjs";
2
+
3
+ export { Scene_default as Scene, loadSceneTable };
@@ -0,0 +1,163 @@
1
+ import { Query, Scene, createField, createModel, uuid } from "@yongdall/model";
2
+ import { useDatabase } from "@yongdall/connection";
3
+ import { hooks } from "@yongdall/core";
4
+
5
+ //#region plugins/scene/models/Scene.mjs
6
+ const SceneField = createModel("scene.field", {
7
+ sceneId: createField("uuid", {
8
+ nullable: false,
9
+ label: "ID",
10
+ primary: 1,
11
+ layout: { hidden: true }
12
+ }),
13
+ model: createField("string", {
14
+ label: "model",
15
+ primary: 2
16
+ }),
17
+ column: createField("string", { label: "Table Field" }),
18
+ field: createField("string", {
19
+ label: "Field",
20
+ primary: 3
21
+ }),
22
+ fixedValue: createField("json", { label: "固定值" }),
23
+ no: createField("i32")
24
+ });
25
+ const SceneTable = createModel("scene.table", {
26
+ sceneId: createField("uuid", {
27
+ nullable: false,
28
+ label: "ID",
29
+ primary: 1,
30
+ layout: { hidden: true }
31
+ }),
32
+ model: createField("string", {
33
+ label: "Model",
34
+ primary: 2
35
+ }),
36
+ table: createField("string", { label: "Table" }),
37
+ no: createField("i32"),
38
+ fields: createField(SceneField, {
39
+ array: true,
40
+ constraints: {
41
+ sceneId: { field: "sceneId" },
42
+ model: { field: "model" },
43
+ no: { noField: true }
44
+ },
45
+ label: "Fields"
46
+ })
47
+ });
48
+ var Scene_default = createModel("scene", {
49
+ id: createField("uuid", {
50
+ nullable: false,
51
+ default: uuid,
52
+ label: "ID",
53
+ primary: 1,
54
+ layout: { hidden: true }
55
+ }),
56
+ label: createField("string", {
57
+ nullable: false,
58
+ default: "",
59
+ label: "Label"
60
+ }),
61
+ dbId: createField("string", {
62
+ nullable: false,
63
+ default: "",
64
+ label: "Database"
65
+ }),
66
+ type: createField("string", {
67
+ nullable: true,
68
+ label: "Type"
69
+ }),
70
+ tables: createField(SceneTable, {
71
+ array: true,
72
+ constraints: {
73
+ sceneId: { field: "id" },
74
+ no: { noField: true }
75
+ },
76
+ label: "tables"
77
+ })
78
+ });
79
+
80
+ //#endregion
81
+ //#region plugins/scene/loadScene.mjs
82
+ /** @import { Fields } from '@yongdall/model' */
83
+ /** @import {SceneType} from './types.mjs' */
84
+ /**
85
+ *
86
+ * @param {Fields} fields
87
+ * @returns {Record<string, SceneType.Field>}
88
+ */
89
+ function toColumns(fields) {
90
+ /** @type {Record<string, SceneType.Field>} */
91
+ const columns = Object.create(null);
92
+ for (const [k, v] of Object.entries(fields)) {
93
+ const { type, array, nullable, primary } = v;
94
+ if (!type) continue;
95
+ const column = v.column || k;
96
+ if (typeof type === "string") {
97
+ columns[column] = {
98
+ type,
99
+ array: array ? 1 : 0,
100
+ nullable,
101
+ primary
102
+ };
103
+ continue;
104
+ }
105
+ if (!type.table) {
106
+ columns[column] = {
107
+ type: "object",
108
+ array: array ? 1 : 0,
109
+ nullable,
110
+ primary: 0
111
+ };
112
+ continue;
113
+ }
114
+ }
115
+ return columns;
116
+ }
117
+ /**
118
+ *
119
+ * @param {SceneType.Define} define
120
+ * @returns {SceneType}
121
+ */
122
+ function toScene({ models, ...define }) {
123
+ const tables = Object.create(null);
124
+ const list = Object.values(models);
125
+ for (let model = list.pop(); model; model = list.pop()) {
126
+ const table = model.table;
127
+ if (typeof table !== "string") continue;
128
+ if (table in tables) continue;
129
+ tables[table] = { fields: toColumns(model.fields) };
130
+ for (const { type } of Object.values(model.fields)) {
131
+ if (!type) continue;
132
+ if (typeof type === "string") continue;
133
+ list.push(type);
134
+ }
135
+ }
136
+ return {
137
+ ...define,
138
+ models: Object.assign(Object.create(null), models),
139
+ tables
140
+ };
141
+ }
142
+ /** @type {Record<string, SceneType>} */
143
+ let scenes = Object.create(null);
144
+ hooks.listen(() => {
145
+ scenes = Object.assign(Object.create(null), Object.entries([...hooks.get("scenes").entriesObject()].map(([plugin, k, v]) => [`${plugin}:${k}`, toScene(v)])));
146
+ }, -1e6);
147
+ /**
148
+ *
149
+ * @param {string} id
150
+ * @param {string} table
151
+ */
152
+ async function loadSceneTable(id, table) {
153
+ /** @type {SceneModel} */
154
+ const sceneDefine = await useDatabase().first(new Query(Scene_default).primary(id));
155
+ if (!sceneDefine) return;
156
+ const sceneModel = scenes[sceneDefine.type].models[table];
157
+ if (!sceneModel || typeof sceneModel.table !== "string") return;
158
+ return new Scene(new Map(sceneDefine.tables.map((t) => [t.table, t]))).table(sceneModel);
159
+ }
160
+
161
+ //#endregion
162
+ export { Scene_default as n, loadSceneTable as t };
163
+ //# sourceMappingURL=loadScene-C7txwTmV.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadScene-C7txwTmV.mjs","names":["SceneModel"],"sources":["../../plugins/scene/models/Scene.mjs","../../plugins/scene/loadScene.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","/** @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":";;;;;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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AAU,SAAY;AACjC,MAAI,SAAS,OAAU;AAEvB,SAAO,SAAS,EAAC,QADF,UAAU,MAAM,OAAO,EACd;AACxB,OAAK,MAAM,EAAC,UAAS,OAAO,OAAO,MAAM,OAAO,EAAE;AACjD,OAAI,CAAC,KAAQ;AACb,OAAI,OAAO,SAAS,SAAY;AAChC,QAAK,KAAK,KAAK;;;AAIjB,QAAO;EACN,GAAG;EACH,QAAQ,OAAO,OAAO,OAAO,OAAO,KAAK,EAAE,OAAO;EAClD;EACA;;;AAGF,IAAW,SAAS,OAAO,OAAO,KAAK;AACvC,MAAM,aAAa;AAClB,UAAS,OAAO,OACf,OAAO,OAAO,KAAK,EACnB,OAAO,QAAQ,CAAC,GAAG,MAAM,IAAI,SAAS,CAAC,eAAe,CAAC,CACrD,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC,CAAC,CAAC,CAC1D;GACC,KAAS;;;;;;AAoBZ,eAAsB,eAAe,IAAI,OAAO;;CAE/C,MAAM,cAAc,MAAM,aAAa,CAAC,MAAM,IAAI,MAAMA,cAAW,CAAC,QAAQ,GAAG,CAAC;AAEhF,KAAI,CAAC,YAAe;CAEpB,MAAM,aADO,OAAO,YAAY,MACR,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 ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@yongdall/scene",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "keywords": [],
6
+ "type": "module",
7
+ "main": "./index.mjs",
8
+ "author": "",
9
+ "license": "ISC",
10
+ "dependencies": {
11
+ "@yongdall/connection": "^0.1.0",
12
+ "@yongdall/model": "^0.1.0",
13
+ "@yongdall/core": "^0.1.0"
14
+ },
15
+ "exports": {
16
+ ".": "./index.mjs"
17
+ }
18
+ }