@yongdall/scene 0.3.0 → 0.5.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.
- package/Scene-B9LbsSn9.mjs +80 -0
- package/Scene-B9LbsSn9.mjs.map +1 -0
- package/index.mjs +2 -1
- package/{loadScene-C7txwTmV.mjs → loadScene-DAFl6Nul.mjs} +4 -79
- package/loadScene-DAFl6Nul.mjs.map +1 -0
- package/package.json +7 -4
- package/yongdall/migration.mjs +10 -0
- package/yongdall/migration.mjs.map +1 -0
- package/yongdall/model.mjs +16 -0
- package/yongdall/model.mjs.map +1 -0
- package/yongdall.plugin.yml +1 -0
- package/hooks.yongdall.mjs +0 -16
- package/hooks.yongdall.mjs.map +0 -1
- package/loadScene-C7txwTmV.mjs.map +0 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createField, createModel, uuid } from "@yongdall/model";
|
|
2
|
+
|
|
3
|
+
//#region plugins/scene/models/Scene.mjs
|
|
4
|
+
const SceneField = createModel("scene.field", {
|
|
5
|
+
sceneId: createField("uuid", {
|
|
6
|
+
nullable: false,
|
|
7
|
+
label: "ID",
|
|
8
|
+
primary: 1,
|
|
9
|
+
layout: { hidden: true }
|
|
10
|
+
}),
|
|
11
|
+
model: createField("string", {
|
|
12
|
+
label: "model",
|
|
13
|
+
primary: 2
|
|
14
|
+
}),
|
|
15
|
+
column: createField("string", { label: "Table Field" }),
|
|
16
|
+
field: createField("string", {
|
|
17
|
+
label: "Field",
|
|
18
|
+
primary: 3
|
|
19
|
+
}),
|
|
20
|
+
fixedValue: createField("json", { label: "固定值" }),
|
|
21
|
+
no: createField("i32")
|
|
22
|
+
});
|
|
23
|
+
const SceneTable = createModel("scene.table", {
|
|
24
|
+
sceneId: createField("uuid", {
|
|
25
|
+
nullable: false,
|
|
26
|
+
label: "ID",
|
|
27
|
+
primary: 1,
|
|
28
|
+
layout: { hidden: true }
|
|
29
|
+
}),
|
|
30
|
+
model: createField("string", {
|
|
31
|
+
label: "Model",
|
|
32
|
+
primary: 2
|
|
33
|
+
}),
|
|
34
|
+
table: createField("string", { label: "Table" }),
|
|
35
|
+
no: createField("i32"),
|
|
36
|
+
fields: createField(SceneField, {
|
|
37
|
+
array: true,
|
|
38
|
+
constraints: {
|
|
39
|
+
sceneId: { field: "sceneId" },
|
|
40
|
+
model: { field: "model" },
|
|
41
|
+
no: { noField: true }
|
|
42
|
+
},
|
|
43
|
+
label: "Fields"
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
var Scene_default = createModel("scene", {
|
|
47
|
+
id: createField("uuid", {
|
|
48
|
+
nullable: false,
|
|
49
|
+
default: uuid,
|
|
50
|
+
label: "ID",
|
|
51
|
+
primary: 1,
|
|
52
|
+
layout: { hidden: true }
|
|
53
|
+
}),
|
|
54
|
+
label: createField("string", {
|
|
55
|
+
nullable: false,
|
|
56
|
+
default: "",
|
|
57
|
+
label: "Label"
|
|
58
|
+
}),
|
|
59
|
+
dbId: createField("string", {
|
|
60
|
+
nullable: false,
|
|
61
|
+
default: "",
|
|
62
|
+
label: "Database"
|
|
63
|
+
}),
|
|
64
|
+
type: createField("string", {
|
|
65
|
+
nullable: true,
|
|
66
|
+
label: "Type"
|
|
67
|
+
}),
|
|
68
|
+
tables: createField(SceneTable, {
|
|
69
|
+
array: true,
|
|
70
|
+
constraints: {
|
|
71
|
+
sceneId: { field: "id" },
|
|
72
|
+
no: { noField: true }
|
|
73
|
+
},
|
|
74
|
+
label: "tables"
|
|
75
|
+
})
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { Scene_default as t };
|
|
80
|
+
//# sourceMappingURL=Scene-B9LbsSn9.mjs.map
|
|
@@ -0,0 +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"}
|
package/index.mjs
CHANGED
|
@@ -1,83 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as Scene_default } from "./Scene-B9LbsSn9.mjs";
|
|
2
|
+
import { Query, Scene } from "@yongdall/model";
|
|
2
3
|
import { useDatabase } from "@yongdall/connection";
|
|
3
4
|
import { hooks } from "@yongdall/core";
|
|
4
5
|
|
|
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
6
|
//#region plugins/scene/loadScene.mjs
|
|
82
7
|
/** @import { Fields } from '@yongdall/model' */
|
|
83
8
|
/** @import {SceneType} from './types.mjs' */
|
|
@@ -159,5 +84,5 @@ async function loadSceneTable(id, table) {
|
|
|
159
84
|
}
|
|
160
85
|
|
|
161
86
|
//#endregion
|
|
162
|
-
export {
|
|
163
|
-
//# sourceMappingURL=loadScene-
|
|
87
|
+
export { loadSceneTable as t };
|
|
88
|
+
//# sourceMappingURL=loadScene-DAFl6Nul.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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.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AI,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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yongdall/scene",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"type": "module",
|
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
"author": "",
|
|
9
9
|
"license": "ISC",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@yongdall/connection": "^0.
|
|
12
|
-
"@yongdall/model": "^0.
|
|
13
|
-
"@yongdall/core": "^0.
|
|
11
|
+
"@yongdall/connection": "^0.5.0",
|
|
12
|
+
"@yongdall/model": "^0.5.0",
|
|
13
|
+
"@yongdall/core": "^0.5.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@yongdall/migrate": "^0.5.0"
|
|
14
17
|
},
|
|
15
18
|
"exports": {
|
|
16
19
|
".": "./index.mjs"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as Scene_default } from "../Scene-B9LbsSn9.mjs";
|
|
2
|
+
|
|
3
|
+
//#region plugins/scene/yongdall/migration.mjs
|
|
4
|
+
/** @import { Profile } from '@yongdall/migrate' */
|
|
5
|
+
/** @type {Profile['models']} */
|
|
6
|
+
const models = [Scene_default];
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { models };
|
|
10
|
+
//# sourceMappingURL=migration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.mjs","names":["Scene"],"sources":["../../../plugins/scene/yongdall/migration.mjs"],"sourcesContent":["/** @import { Profile } from '@yongdall/migrate' */\nimport Scene from '../models/Scene.mjs';\n\n\n/** @type {Profile['models']} */\nexport const models = [\n\tScene\n]\n"],"mappings":";;;;;AAKA,MAAa,SAAS,CACrBA,cACA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { t as Scene_default } from "../Scene-B9LbsSn9.mjs";
|
|
2
|
+
import { t as loadSceneTable } from "../loadScene-DAFl6Nul.mjs";
|
|
3
|
+
|
|
4
|
+
//#region plugins/scene/yongdall/model.mjs
|
|
5
|
+
/** @import { ModelProfile } from '@yongdall/core' */
|
|
6
|
+
/** @type {ModelProfile['models']} */
|
|
7
|
+
const models = { scene: Scene_default };
|
|
8
|
+
/** @type {ModelProfile['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 { modelLoaders, models };
|
|
16
|
+
//# sourceMappingURL=model.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.mjs","names":["Scene"],"sources":["../../../plugins/scene/yongdall/model.mjs"],"sourcesContent":["/** @import { ModelProfile } from '@yongdall/core' */\nimport { loadSceneTable } from '../loadScene.mjs';\nimport Scene from '../models/Scene.mjs';\n\n/** @type {ModelProfile['models']} */\nexport const models = {\n\tscene: Scene,\n};\n\n/** @type {ModelProfile['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":";;;;;;AAKA,MAAa,SAAS,EACrB,OAAOA,eACP;;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
label: 场景支持
|
package/hooks.yongdall.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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
|
package/hooks.yongdall.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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;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