lecodes-sdk 2.0.4 → 2.0.6

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.
Files changed (72) hide show
  1. package/README.md +104 -76
  2. package/dist/global.d.ts +2 -5
  3. package/dist/host.d.ts +3 -0
  4. package/dist/types/inject.d.ts +3 -3
  5. package/dist/types/runtime/device.d.ts +7 -0
  6. package/dist/types/runtime/rpc.d.ts +11 -17
  7. package/dist/types/runtime/wire.d.ts +53 -0
  8. package/dist/types/server/auth/api.d.ts +42 -0
  9. package/dist/types/server/auth/appConfig.d.ts +1 -5
  10. package/dist/types/server/auth/models.d.ts +119 -70
  11. package/dist/types/server/auth/types.d.ts +19 -43
  12. package/dist/types/server/channel.d.ts +57 -19
  13. package/dist/types/server/context.d.ts +2 -2
  14. package/dist/types/server/db/defineDb.d.ts +10 -0
  15. package/dist/types/server/db/index.d.ts +1 -1
  16. package/dist/types/server/db/types.d.ts +76 -6
  17. package/dist/types/server/inject.d.ts +0 -1
  18. package/dist/types/ui/UINode.d.ts +19 -5
  19. package/dist/types/ui/UIScreen.d.ts +1 -0
  20. package/dist/types/ui/UITabs.d.ts +8 -6
  21. package/dist/types/ui/theme.d.ts +48 -13
  22. package/dist/types/version.d.ts +1 -1
  23. package/dist/types.json +1 -1
  24. package/package.json +3 -2
  25. package/prompts/README.md +1 -1
  26. package/prompts/design.md +19 -19
  27. package/prompts/dist/2d-game.md +45 -31
  28. package/prompts/dist/3d-app.md +45 -31
  29. package/prompts/dist/ar-app.md +45 -31
  30. package/prompts/dist/design.md +25 -24
  31. package/prompts/dist/ui-app.md +45 -31
  32. package/prompts/ui-design.md +6 -5
  33. package/prompts/ui.md +25 -22
  34. package/src/bridges/device.d.ts +9 -0
  35. package/src/bridges/tree.d.ts +5 -0
  36. package/src/chisel.ts +1 -1
  37. package/src/compile/bundler.ts +6 -0
  38. package/src/compile/compileProject.ts +3 -1
  39. package/src/compile/index.ts +3 -1
  40. package/src/compile/serverSplit.ts +58 -11
  41. package/src/compile/serverTypes.ts +189 -8
  42. package/src/host.d.ts +3 -0
  43. package/src/inject.ts +6 -6
  44. package/src/runtime/device.ts +12 -0
  45. package/src/runtime/rpc.ts +101 -40
  46. package/src/runtime/wire.ts +35 -0
  47. package/src/server/auth/api.ts +94 -0
  48. package/src/server/auth/appConfig.ts +2 -3
  49. package/src/server/auth/host.ts +244 -174
  50. package/src/server/auth/models.ts +45 -62
  51. package/src/server/auth/types.ts +19 -34
  52. package/src/server/channel.ts +97 -29
  53. package/src/server/channelHub.ts +153 -0
  54. package/src/server/context.ts +2 -2
  55. package/src/server/db/defineDb.ts +96 -36
  56. package/src/server/db/index.ts +1 -1
  57. package/src/server/db/types.ts +76 -8
  58. package/src/server/host.ts +25 -10
  59. package/src/server/inject.ts +2 -2
  60. package/src/server/runtime.ts +34 -12
  61. package/src/ui/UINode.ts +22 -5
  62. package/src/ui/UIScreen.ts +5 -0
  63. package/src/ui/UITabs.ts +19 -17
  64. package/src/ui/styleColor.ts +10 -1
  65. package/src/ui/theme.ts +96 -41
  66. package/src/version.ts +1 -1
  67. package/tests/helpers/fakeTree.ts +1 -0
  68. package/dist/types/plugins/oauth.d.ts +0 -25
  69. package/dist/types/server/auth/global.d.ts +0 -56
  70. package/src/plugins/oauth.ts +0 -61
  71. package/src/server/auth/global.ts +0 -80
  72. package/tests/helpers/memoryMarci.ts +0 -124
@@ -1,124 +0,0 @@
1
- /**
2
- * An in-memory `MarciTransport` for tests: enough of marcidb's query language for the auth runtime and
3
- * simple endpoint tests (equality `$where` on scalars and `one` relations, `$and`, `$order`/`$limit`/
4
- * `$skip`, select shapes with nested `one` selects, `$increment`, updateMany/deleteMany, count, batch).
5
- * Defaults come from the model definitions. Not a marcidb — the e2e test against the real engine is
6
- * the source of truth; this makes the flows runnable everywhere.
7
- */
8
- import type { MarciOp, MarciTransport } from "../../src/server/db/marci/query"
9
- import type { Field, FieldDef } from "../../src/server/db/fields"
10
- import type { Model } from "../../src/server/db/types"
11
-
12
- type Row = Record<string, any>
13
-
14
- export const memoryMarci = (models: Record<string, Model> | (() => Record<string, Model>)) => {
15
- const modelsOf = typeof models === "function" ? models : () => models
16
- const tables = new Map<string, Row[]>()
17
- const nextId = new Map<string, number>()
18
- const defs = (model: string): Record<string, FieldDef> =>
19
- Object.fromEntries(Object.entries(modelsOf()[model]?.fields ?? {}).map(([k, f]) => [k, (f as Field<any, any>).def]))
20
- const rows = (model: string) => { let t = tables.get(model); if (!t) { t = []; tables.set(model, t) } return t }
21
- const ops: MarciOp[] = []
22
-
23
- const matchesField = (row: Row, key: string, cond: any, d: FieldDef | undefined): boolean => {
24
- const v = row[key]
25
- if (d && (d.kind === "one")) {
26
- if (cond === null) return v === null || v === undefined
27
- if (typeof cond === "object" && "id" in cond) return v?.id === cond.id
28
- if (typeof cond === "object" && "$not" in cond) return !matchesField(row, key, cond.$not, d)
29
- throw new Error(`memoryMarci: unsupported relation condition ${JSON.stringify(cond)}`)
30
- }
31
- if (cond !== null && typeof cond === "object" && !Array.isArray(cond)) {
32
- for (const [op, x] of Object.entries(cond)) {
33
- switch (op) {
34
- case "$eq": if (v !== x) return false; break
35
- case "$ne": case "$not": if (v === x) return false; break
36
- case "$in": if (!(x as any[]).includes(v)) return false; break
37
- case "$gt": if (!(v > (x as any))) return false; break
38
- case "$gte": if (!(v >= (x as any))) return false; break
39
- case "$lt": if (!(v < (x as any))) return false; break
40
- case "$lte": if (!(v <= (x as any))) return false; break
41
- default: throw new Error(`memoryMarci: unsupported operator ${op}`)
42
- }
43
- }
44
- return true
45
- }
46
- return v === cond
47
- }
48
- const matches = (model: string, row: Row, where: any): boolean => {
49
- if (!where) return true
50
- if (where.$and) return where.$and.every((w: any) => matches(model, row, w))
51
- if (where.$or) return where.$or.some((w: any) => matches(model, row, w))
52
- if (where.$not) return !matches(model, row, where.$not)
53
- const d = defs(model)
54
- return Object.entries(where).every(([k, c]) => matchesField(row, k, c, d[k]))
55
- }
56
- const project = (model: string, row: Row, shape: Record<string, any>): Row => {
57
- const out: Row = {}
58
- const d = defs(model)
59
- for (const [k, v] of Object.entries(shape)) {
60
- if (k.startsWith("$") || v === false || v === undefined) continue
61
- const def = d[k]
62
- if (def?.kind === "one") {
63
- const ref = row[k]
64
- if (!ref) { out[k] = null; continue }
65
- const target = rows(def.model!).find(r => r.id === ref.id)
66
- out[k] = target ? (v === true ? { id: target.id } : project(def.model!, target, v)) : null
67
- continue
68
- }
69
- out[k] = row[k] === undefined ? null : row[k]
70
- }
71
- return out
72
- }
73
- const select = (model: string, q: Record<string, any>): Row[] => {
74
- let list = rows(model).filter(r => matches(model, r, q.$where))
75
- if (q.$order) {
76
- const [[f, dir]] = Object.entries(q.$order) as [string, string][]
77
- list = [...list].sort((a, b) => (a[f] < b[f] ? -1 : a[f] > b[f] ? 1 : 0) * (dir === "desc" ? -1 : 1))
78
- }
79
- if (q.$skip) list = list.slice(q.$skip)
80
- if (q.$limit !== undefined) list = list.slice(0, q.$limit)
81
- return list.map(r => project(model, r, q))
82
- }
83
- const applyUpdate = (model: string, row: Row, data: Row) => {
84
- const d = defs(model)
85
- for (const [k, v] of Object.entries(data)) {
86
- if (v !== null && typeof v === "object" && "$increment" in v) { row[k] = (row[k] ?? 0) + v.$increment; continue }
87
- if (d[k]?.kind === "one") { row[k] = v === null ? null : { id: (v as any).id ?? (v as any).$connect?.id }; continue }
88
- row[k] = v
89
- }
90
- }
91
- const insert = (model: string, data: Row): Row => {
92
- const d = defs(model)
93
- const id = (nextId.get(model) ?? 0) + 1
94
- nextId.set(model, id)
95
- const row: Row = { id }
96
- for (const [k, def] of Object.entries(d)) {
97
- if (def.kind === "many" || def.kind === "list") continue
98
- if (k in data && data[k] !== undefined) { row[k] = def.kind === "one" ? { id: data[k].id } : data[k]; continue }
99
- if (def.hasDefault) { row[k] = def.default === "now" ? Date.now() : def.default; continue }
100
- row[k] = null
101
- }
102
- rows(model).push(row)
103
- return row
104
- }
105
- const idOf = (id: any) => (typeof id === "object" ? id.id : id)
106
-
107
- const exec = async (op: MarciOp): Promise<any> => {
108
- ops.push(op)
109
- const { model, action } = op
110
- switch (action) {
111
- case "insert": return { id: insert(model, op.data).id }
112
- case "findMany": return select(model, op.query ?? {})
113
- case "findFirst": return select(model, { ...(op.query ?? {}), $limit: 1 })[0] ?? null
114
- case "update": { const r = rows(model).find(r => r.id === idOf(op.id)); if (!r) throw new Error("not found"); applyUpdate(model, r, op.data); return null }
115
- case "updateMany": { let n = 0; for (const r of rows(model)) if (matches(model, r, op.query?.$where)) { applyUpdate(model, r, op.data); n++ } return n }
116
- case "delete": { const t = rows(model); const i = t.findIndex(r => r.id === idOf(op.id)); if (i >= 0) t.splice(i, 1); return i >= 0 }
117
- case "deleteMany": { const t = rows(model); const keep = t.filter(r => !matches(model, r, op.query?.$where)); const n = t.length - keep.length; tables.set(model, keep); return n }
118
- case "count": return rows(model).filter(r => matches(model, r, op.query?.$where)).length
119
- default: throw new Error(`memoryMarci: unsupported action ${action}`)
120
- }
121
- }
122
- const transport: MarciTransport = { exec, batch: async (batch) => { const out = []; for (const op of batch) out.push(await exec(op)); return out } }
123
- return { transport, ops, rows, tables }
124
- }