@zaflun/lumio-sdk 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,138 @@
1
+ interface Validator {
2
+ type: string;
3
+ isOptional: boolean;
4
+ optional(): Validator;
5
+ items?: Validator;
6
+ shape?: Record<string, Validator>;
7
+ }
8
+ declare const v: {
9
+ string(): Validator;
10
+ number(): Validator;
11
+ boolean(): Validator;
12
+ array(items: Validator): Validator;
13
+ object(shape: Record<string, Validator>): Validator;
14
+ };
15
+
16
+ interface TableDefinition {
17
+ columns: Record<string, Validator>;
18
+ storageScope: string;
19
+ storage(scope: string): TableDefinition;
20
+ }
21
+ interface SchemaDefinition {
22
+ tables: Record<string, TableDefinition>;
23
+ }
24
+ declare function defineTable(columns: Record<string, Validator>): TableDefinition;
25
+ declare function defineSchema(tables: Record<string, TableDefinition>): SchemaDefinition;
26
+
27
+ interface QueryRowsDefinition {
28
+ __type: "queryRows";
29
+ table: string;
30
+ }
31
+ declare function queryRows(table: string): QueryRowsDefinition;
32
+
33
+ interface InsertRowDefinition {
34
+ __type: "insertRow";
35
+ table: string;
36
+ values: Record<string, unknown>;
37
+ editorOnly: boolean;
38
+ }
39
+ interface InsertRowOptions {
40
+ editorOnly?: boolean;
41
+ }
42
+ declare function insertRow(table: string, values: Record<string, unknown>, opts?: InsertRowOptions): InsertRowDefinition;
43
+
44
+ interface PatchRowDefinition {
45
+ __type: "patchRow";
46
+ table: string;
47
+ rowId: string;
48
+ values: Record<string, unknown>;
49
+ editorOnly: boolean;
50
+ }
51
+ interface PatchRowOptions {
52
+ editorOnly?: boolean;
53
+ }
54
+ declare function patchRow(table: string, rowId: string, values: Record<string, unknown>, opts?: PatchRowOptions): PatchRowDefinition;
55
+
56
+ interface DeleteRowDefinition {
57
+ __type: "deleteRow";
58
+ table: string;
59
+ rowId: string;
60
+ editorOnly: boolean;
61
+ }
62
+ interface DeleteRowOptions {
63
+ editorOnly?: boolean;
64
+ }
65
+ declare function deleteRow(table: string, rowId: string, opts?: DeleteRowOptions): DeleteRowDefinition;
66
+
67
+ interface HandlerContext {
68
+ db: {
69
+ get: (table: string, id: string) => Promise<Record<string, unknown> | null>;
70
+ insert: (table: string, values: Record<string, unknown>) => Promise<string>;
71
+ patch: (table: string, id: string, values: Record<string, unknown>) => Promise<void>;
72
+ delete: (table: string, id: string) => Promise<void>;
73
+ };
74
+ fetch: (url: string, opts?: RequestInit) => Promise<Response>;
75
+ auth: {
76
+ userId: string | null;
77
+ accountId: string | null;
78
+ };
79
+ secrets: {
80
+ get: (name: string) => Promise<string | null>;
81
+ };
82
+ }
83
+ interface HandlerConfig {
84
+ args: Record<string, Validator>;
85
+ handler: (ctx: HandlerContext, args: Record<string, unknown>) => Promise<unknown>;
86
+ }
87
+ interface QueryDefinition {
88
+ __type: "query";
89
+ args: Record<string, Validator>;
90
+ handler: HandlerConfig["handler"];
91
+ }
92
+ interface MutationDefinition {
93
+ __type: "mutation";
94
+ args: Record<string, Validator>;
95
+ handler: HandlerConfig["handler"];
96
+ }
97
+ interface ActionDefinition {
98
+ __type: "action";
99
+ args: Record<string, Validator>;
100
+ handler: HandlerConfig["handler"];
101
+ }
102
+ declare function query(config: HandlerConfig): QueryDefinition;
103
+ declare function mutation(config: HandlerConfig): MutationDefinition;
104
+ declare function action(config: HandlerConfig): ActionDefinition;
105
+
106
+ interface FetchActionDefinition {
107
+ __type: "fetchAction";
108
+ url: string;
109
+ method: string;
110
+ headers?: Record<string, string>;
111
+ body?: unknown;
112
+ }
113
+ interface FetchActionOptions {
114
+ method?: string;
115
+ headers?: Record<string, string>;
116
+ body?: unknown;
117
+ }
118
+ declare function fetchAction(url: string, opts?: FetchActionOptions): FetchActionDefinition;
119
+
120
+ declare function arg(name: string): {
121
+ __expr: "arg";
122
+ name: string;
123
+ };
124
+ declare function identity(): {
125
+ __expr: "identity";
126
+ };
127
+ declare function secret(name: string): {
128
+ __expr: "secret";
129
+ name: string;
130
+ };
131
+ declare function filter(field: string, op: string, value: unknown): {
132
+ __expr: "filter";
133
+ field: string;
134
+ op: string;
135
+ value: unknown;
136
+ };
137
+
138
+ export { type ActionDefinition, type DeleteRowDefinition, type DeleteRowOptions, type FetchActionDefinition, type FetchActionOptions, type HandlerConfig, type HandlerContext, type InsertRowDefinition, type InsertRowOptions, type MutationDefinition, type PatchRowDefinition, type PatchRowOptions, type QueryDefinition, type QueryRowsDefinition, type SchemaDefinition, type TableDefinition, type Validator, action, arg, defineSchema, defineTable, deleteRow, fetchAction, filter, identity, insertRow, mutation, patchRow, query, queryRows, secret, v };
package/dist/server.js ADDED
@@ -0,0 +1,131 @@
1
+ // src/server/schema.ts
2
+ function defineTable(columns) {
3
+ const table = {
4
+ columns,
5
+ storageScope: "instance",
6
+ storage(scope) {
7
+ return { ...this, storageScope: scope };
8
+ }
9
+ };
10
+ return table;
11
+ }
12
+ function defineSchema(tables) {
13
+ return { tables };
14
+ }
15
+
16
+ // src/server/validators.ts
17
+ function createValidator(type) {
18
+ return {
19
+ type,
20
+ isOptional: false,
21
+ optional() {
22
+ return { ...this, isOptional: true };
23
+ }
24
+ };
25
+ }
26
+ var v = {
27
+ string() {
28
+ return createValidator("string");
29
+ },
30
+ number() {
31
+ return createValidator("number");
32
+ },
33
+ boolean() {
34
+ return createValidator("boolean");
35
+ },
36
+ array(items) {
37
+ return { ...createValidator("array"), items };
38
+ },
39
+ object(shape) {
40
+ return { ...createValidator("object"), shape };
41
+ }
42
+ };
43
+
44
+ // src/server/queryRows.ts
45
+ function queryRows(table) {
46
+ return { __type: "queryRows", table };
47
+ }
48
+
49
+ // src/server/insertRow.ts
50
+ function insertRow(table, values, opts) {
51
+ return {
52
+ __type: "insertRow",
53
+ table,
54
+ values,
55
+ editorOnly: opts?.editorOnly ?? false
56
+ };
57
+ }
58
+
59
+ // src/server/patchRow.ts
60
+ function patchRow(table, rowId, values, opts) {
61
+ return {
62
+ __type: "patchRow",
63
+ table,
64
+ rowId,
65
+ values,
66
+ editorOnly: opts?.editorOnly ?? false
67
+ };
68
+ }
69
+
70
+ // src/server/deleteRow.ts
71
+ function deleteRow(table, rowId, opts) {
72
+ return {
73
+ __type: "deleteRow",
74
+ table,
75
+ rowId,
76
+ editorOnly: opts?.editorOnly ?? false
77
+ };
78
+ }
79
+
80
+ // src/server/handlers.ts
81
+ function query(config) {
82
+ return { __type: "query", args: config.args, handler: config.handler };
83
+ }
84
+ function mutation(config) {
85
+ return { __type: "mutation", args: config.args, handler: config.handler };
86
+ }
87
+ function action(config) {
88
+ return { __type: "action", args: config.args, handler: config.handler };
89
+ }
90
+
91
+ // src/server/fetchAction.ts
92
+ function fetchAction(url, opts) {
93
+ return {
94
+ __type: "fetchAction",
95
+ url,
96
+ method: opts?.method ?? "GET",
97
+ headers: opts?.headers,
98
+ body: opts?.body
99
+ };
100
+ }
101
+
102
+ // src/server/expressions.ts
103
+ function arg(name) {
104
+ return { __expr: "arg", name };
105
+ }
106
+ function identity() {
107
+ return { __expr: "identity" };
108
+ }
109
+ function secret(name) {
110
+ return { __expr: "secret", name };
111
+ }
112
+ function filter(field, op, value) {
113
+ return { __expr: "filter", field, op, value };
114
+ }
115
+ export {
116
+ action,
117
+ arg,
118
+ defineSchema,
119
+ defineTable,
120
+ deleteRow,
121
+ fetchAction,
122
+ filter,
123
+ identity,
124
+ insertRow,
125
+ mutation,
126
+ patchRow,
127
+ query,
128
+ queryRows,
129
+ secret,
130
+ v
131
+ };
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@zaflun/lumio-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Lumio Extension SDK — React components, hooks, and server utilities for building Lumio extensions",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./server": {
14
+ "import": "./dist/server.js",
15
+ "types": "./dist/server.d.ts"
16
+ },
17
+ "./runtime": {
18
+ "import": "./dist/lumio-runtime.global.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "react-reconciler": "^0.32.0",
26
+ "@zaflun/lumio-extension-types": "0.1.0",
27
+ "@zaflun/lumio-protocol": "0.1.1"
28
+ },
29
+ "peerDependencies": {
30
+ "react": "^18.0.0 || ^19.0.0",
31
+ "react-dom": "^18.0.0 || ^19.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@testing-library/react": "^16.1.0",
35
+ "@types/react": "^19.1.0",
36
+ "@types/react-dom": "^19.1.0",
37
+ "@types/react-reconciler": "^0.32.0",
38
+ "jsdom": "^26.1.0",
39
+ "react": "^19.1.0",
40
+ "react-dom": "^19.1.0",
41
+ "tsup": "^8.4.0",
42
+ "typescript": "^5.8.3",
43
+ "vitest": "^3.1.4"
44
+ },
45
+ "license": "MIT",
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "author": {
50
+ "name": "zaflun",
51
+ "email": "developers@zaflun.com",
52
+ "url": "https://withzaflun.com"
53
+ },
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "https://github.com/zaflun/lumio.git",
57
+ "directory": "packages/sdk"
58
+ },
59
+ "homepage": "https://developers.lumio.vision",
60
+ "bugs": {
61
+ "url": "https://github.com/zaflun/lumio/issues",
62
+ "email": "developers@zaflun.com"
63
+ },
64
+ "scripts": {
65
+ "build": "tsup src/index.ts src/server.ts --format esm --dts --clean && pnpm build:runtime",
66
+ "build:runtime": "tsup --config tsup.runtime.ts",
67
+ "test": "vitest run",
68
+ "test:watch": "vitest",
69
+ "lint": "eslint src/",
70
+ "typecheck": "tsc --noEmit"
71
+ }
72
+ }