@surfaces-ui/dev-server 0.0.0-stage → 0.2.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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +30 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +44 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +217 -0
- package/dist/config.js +203 -0
- package/dist/config.js.map +1 -0
- package/dist/env.d.ts +13 -0
- package/dist/env.js +27 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/pipelines-cli.d.ts +2 -0
- package/dist/pipelines-cli.js +126 -0
- package/dist/pipelines-cli.js.map +1 -0
- package/dist/server.d.ts +106 -0
- package/dist/server.js +272 -0
- package/dist/server.js.map +1 -0
- package/dist/store.d.ts +7 -0
- package/dist/store.js +88 -0
- package/dist/store.js.map +1 -0
- package/dist/stores.d.ts +34 -0
- package/dist/stores.js +170 -0
- package/dist/stores.js.map +1 -0
- package/package.json +73 -3
package/dist/stores.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { create, fromJson, toJson } from "@bufbuild/protobuf";
|
|
4
|
+
import { formDefinitions, memoryForms, memorySemantics, memorySurfaceLibrary } from "@surfaces-ui/data";
|
|
5
|
+
import { ListSubmissionsResponseSchema, RunSchema, SubmissionSchema } from "@surfaces-ui/proto";
|
|
6
|
+
const ID = /^[a-z0-9][a-z0-9-]{0,80}$/;
|
|
7
|
+
/**
|
|
8
|
+
* Keeps saved surfaces as one JSON file each in a folder, every version in
|
|
9
|
+
* the file, so they can be reviewed and committed like other project files.
|
|
10
|
+
*/
|
|
11
|
+
export function fileLibraryStorage(dir, idPattern = ID) {
|
|
12
|
+
return {
|
|
13
|
+
load() {
|
|
14
|
+
if (!fs.existsSync(dir))
|
|
15
|
+
return undefined;
|
|
16
|
+
const all = {};
|
|
17
|
+
for (const file of fs.readdirSync(dir).filter((f) => f.endsWith(".json"))) {
|
|
18
|
+
try {
|
|
19
|
+
all[file.slice(0, -5)] = JSON.parse(fs.readFileSync(path.join(dir, file), "utf8"));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// A file that does not parse is left alone and not offered.
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return JSON.stringify(all);
|
|
26
|
+
},
|
|
27
|
+
save(_key, value) {
|
|
28
|
+
const all = JSON.parse(value);
|
|
29
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
30
|
+
for (const [id, versions] of Object.entries(all)) {
|
|
31
|
+
if (!idPattern.test(id))
|
|
32
|
+
continue;
|
|
33
|
+
fs.writeFileSync(path.join(dir, `${id}.json`), `${JSON.stringify(versions, null, 2)}\n`);
|
|
34
|
+
}
|
|
35
|
+
for (const file of fs.readdirSync(dir).filter((f) => f.endsWith(".json"))) {
|
|
36
|
+
if (!Object.hasOwn(all, file.slice(0, -5)))
|
|
37
|
+
fs.rmSync(path.join(dir, file), { force: true });
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function fileSurfaceLibrary(dir) {
|
|
43
|
+
return memorySurfaceLibrary({ storage: fileLibraryStorage(dir) });
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Semantic models as one JSON file each in a folder (`<name>.json`, every
|
|
47
|
+
* kept version in it, in the contract's JSON form), so a project's models
|
|
48
|
+
* are reviewed and committed like its other files.
|
|
49
|
+
*/
|
|
50
|
+
export function fileSemantics(dir, options = {}) {
|
|
51
|
+
return memorySemantics({ ...options, storage: fileLibraryStorage(dir, /^[a-z][a-z0-9_]{0,63}$/) });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Forms whose submissions are appended to one JSON-lines file per form in a
|
|
55
|
+
* folder. Values are checked against the form's fields before anything is
|
|
56
|
+
* written; nothing a client sends chooses the file.
|
|
57
|
+
*/
|
|
58
|
+
export function fileForms(dir, forms) {
|
|
59
|
+
const fileOf = (formId) => path.join(dir, `${formId}.jsonl`);
|
|
60
|
+
let counter = Date.now();
|
|
61
|
+
const inner = memoryForms({
|
|
62
|
+
forms: formDefinitions(forms),
|
|
63
|
+
// Unique across restarts, unlike a counter from 1.
|
|
64
|
+
newId: () => `sub-${(counter++).toString(36)}`,
|
|
65
|
+
onSubmit(submission) {
|
|
66
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
67
|
+
fs.appendFileSync(fileOf(submission.formId), `${JSON.stringify(toJson(SubmissionSchema, submission))}\n`);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
const read = (formId) => {
|
|
71
|
+
if (!ID.test(formId) || !fs.existsSync(fileOf(formId)))
|
|
72
|
+
return [];
|
|
73
|
+
return fs
|
|
74
|
+
.readFileSync(fileOf(formId), "utf8")
|
|
75
|
+
.split("\n")
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
.flatMap((line) => {
|
|
78
|
+
try {
|
|
79
|
+
return [fromJson(SubmissionSchema, JSON.parse(line))];
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
...inner,
|
|
88
|
+
async listSubmissions(request) {
|
|
89
|
+
const ids = request.formId ? [request.formId] : forms.map((f) => f.id);
|
|
90
|
+
const all = ids.flatMap(read).sort((a, b) => b.submittedAt.localeCompare(a.submittedAt));
|
|
91
|
+
const start = request.pageToken ? Number(request.pageToken) : 0;
|
|
92
|
+
const size = request.pageSize || 100;
|
|
93
|
+
return create(ListSubmissionsResponseSchema, { submissions: all.slice(start, start + size), nextPageToken: start + size < all.length ? String(start + size) : "" });
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const PIPELINE_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,80}$/;
|
|
98
|
+
/**
|
|
99
|
+
* Pipelines a person approved, as one JSON file each in a folder
|
|
100
|
+
* (`<id>.json`, every version in it), so they are reviewed and committed like
|
|
101
|
+
* other project files. Only the runner writes here, after its checks.
|
|
102
|
+
*/
|
|
103
|
+
export function filePipelineStore(dir) {
|
|
104
|
+
return {
|
|
105
|
+
async list() {
|
|
106
|
+
if (!fs.existsSync(dir))
|
|
107
|
+
return [];
|
|
108
|
+
return fs
|
|
109
|
+
.readdirSync(dir)
|
|
110
|
+
.filter((f) => f.endsWith(".json") && PIPELINE_ID.test(f.slice(0, -5)))
|
|
111
|
+
.flatMap((file) => {
|
|
112
|
+
try {
|
|
113
|
+
const saved = JSON.parse(fs.readFileSync(path.join(dir, file), "utf8"));
|
|
114
|
+
return saved?.definition?.id === file.slice(0, -5) ? [saved] : [];
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// A file that does not parse is left alone and not offered.
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
async put(saved) {
|
|
123
|
+
if (!PIPELINE_ID.test(saved.definition.id))
|
|
124
|
+
throw new Error(`Not a pipeline ID: ${saved.definition.id}`);
|
|
125
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
126
|
+
fs.writeFileSync(path.join(dir, `${saved.definition.id}.json`), `${JSON.stringify(saved, null, 2)}\n`);
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Runs kept as one JSON file per pipeline in a folder, newest first and at
|
|
132
|
+
* most `limit` of them, so history outlives a restart. A run is written as it
|
|
133
|
+
* changes; the last write wins, so one server should own a folder.
|
|
134
|
+
*/
|
|
135
|
+
export function fileRunStore(dir, limit = 50) {
|
|
136
|
+
const fileOf = (pipelineId) => path.join(dir, `${pipelineId}.json`);
|
|
137
|
+
const read = (file) => {
|
|
138
|
+
try {
|
|
139
|
+
return JSON.parse(fs.readFileSync(file, "utf8")).map((run) => fromJson(RunSchema, run, { ignoreUnknownFields: true }));
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
async load() {
|
|
147
|
+
if (!fs.existsSync(dir))
|
|
148
|
+
return [];
|
|
149
|
+
return fs
|
|
150
|
+
.readdirSync(dir)
|
|
151
|
+
.filter((f) => f.endsWith(".json"))
|
|
152
|
+
.flatMap((f) => read(path.join(dir, f)))
|
|
153
|
+
.sort((a, b) => b.startTime.localeCompare(a.startTime));
|
|
154
|
+
},
|
|
155
|
+
async save(run) {
|
|
156
|
+
if (!PIPELINE_ID.test(run.pipelineId))
|
|
157
|
+
return;
|
|
158
|
+
const file = fileOf(run.pipelineId);
|
|
159
|
+
const runs = fs.existsSync(file) ? read(file) : [];
|
|
160
|
+
const index = runs.findIndex((r) => r.id === run.id);
|
|
161
|
+
if (index >= 0)
|
|
162
|
+
runs[index] = run;
|
|
163
|
+
else
|
|
164
|
+
runs.unshift(run);
|
|
165
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
166
|
+
fs.writeFileSync(file, `${JSON.stringify(runs.slice(0, limit).map((r) => toJson(RunSchema, r)), null, 1)}\n`);
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=stores.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stores.js","sourceRoot":"","sources":["../src/stores.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAyB,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACrF,OAAO,EAAkH,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAExN,OAAO,EAAE,6B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AAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;YACrD,IAAI,KAAK,IAAI,CAAC;gBAAE,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;;gBAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACvB,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACvC,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;QAChH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { type MessageInitShape, create, fromJson, toJson } from \"@bufbuild/protobuf\";\nimport { type FormSpec, type Forms, type StateStorage, type MemorySemanticsOptions, type Semantics, type SurfaceLibrary, formDefinitions, memoryForms, memorySemantics, memorySurfaceLibrary } from \"@surfaces-ui/data\";\nimport type { PipelineStore, RunStore, SavedPipeline } from \"@surfaces-ui/pipelines\";\nimport { ListSubmissionsResponseSchema, type Run, RunSchema, type Submission, SubmissionSchema } from \"@surfaces-ui/proto\";\n\nconst ID = /^[a-z0-9][a-z0-9-]{0,80}$/;\n\n/**\n * Keeps saved surfaces as one JSON file each in a folder, every version in\n * the file, so they can be reviewed and committed like other project files.\n */\nexport function fileLibraryStorage(dir: string, idPattern: RegExp = ID): StateStorage {\n return {\n load() {\n if (!fs.existsSync(dir)) return undefined;\n const all: Record<string, unknown> = {};\n for (const file of fs.readdirSync(dir).filter((f) => f.endsWith(\".json\"))) {\n try {\n all[file.slice(0, -5)] = JSON.parse(fs.readFileSync(path.join(dir, file), \"utf8\"));\n } catch {\n // A file that does not parse is left alone and not offered.\n }\n }\n return JSON.stringify(all);\n },\n save(_key, value) {\n const all = JSON.parse(value) as Record<string, unknown>;\n fs.mkdirSync(dir, { recursive: true });\n for (const [id, versions] of Object.entries(all)) {\n if (!idPattern.test(id)) continue;\n fs.writeFileSync(path.join(dir, `${id}.json`), `${JSON.stringify(versions, null, 2)}\\n`);\n }\n for (const file of fs.readdirSync(dir).filter((f) => f.endsWith(\".json\"))) {\n if (!Object.hasOwn(all, file.slice(0, -5))) fs.rmSync(path.join(dir, file), { force: true });\n }\n },\n };\n}\n\nexport function fileSurfaceLibrary(dir: string): SurfaceLibrary {\n return memorySurfaceLibrary({ storage: fileLibraryStorage(dir) });\n}\n\n/**\n * Semantic models as one JSON file each in a folder (`<name>.json`, every\n * kept version in it, in the contract's JSON form), so a project's models\n * are reviewed and committed like its other files.\n */\nexport function fileSemantics(dir: string, options: Omit<MemorySemanticsOptions, \"storage\"> = {}): Semantics {\n return memorySemantics({ ...options, storage: fileLibraryStorage(dir, /^[a-z][a-z0-9_]{0,63}$/) });\n}\n\n/** A form as `surfaces.config.ts` declares it. */\nexport type FormConfig = FormSpec;\n\n/**\n * Forms whose submissions are appended to one JSON-lines file per form in a\n * folder. Values are checked against the form's fields before anything is\n * written; nothing a client sends chooses the file.\n */\nexport function fileForms(dir: string, forms: FormConfig[]): Forms {\n const fileOf = (formId: string) => path.join(dir, `${formId}.jsonl`);\n let counter = Date.now();\n const inner = memoryForms({\n forms: formDefinitions(forms),\n // Unique across restarts, unlike a counter from 1.\n newId: () => `sub-${(counter++).toString(36)}`,\n onSubmit(submission) {\n fs.mkdirSync(dir, { recursive: true });\n fs.appendFileSync(fileOf(submission.formId), `${JSON.stringify(toJson(SubmissionSchema, submission))}\\n`);\n },\n });\n const read = (formId: string): Submission[] => {\n if (!ID.test(formId) || !fs.existsSync(fileOf(formId))) return [];\n return fs\n .readFileSync(fileOf(formId), \"utf8\")\n .split(\"\\n\")\n .filter(Boolean)\n .flatMap((line) => {\n try {\n return [fromJson(SubmissionSchema, JSON.parse(line))];\n } catch {\n return [];\n }\n });\n };\n return {\n ...inner,\n async listSubmissions(request) {\n const ids = request.formId ? [request.formId] : forms.map((f) => f.id);\n const all = ids.flatMap(read).sort((a, b) => b.submittedAt.localeCompare(a.submittedAt));\n const start = request.pageToken ? Number(request.pageToken) : 0;\n const size = request.pageSize || 100;\n return create(ListSubmissionsResponseSchema, { submissions: all.slice(start, start + size), nextPageToken: start + size < all.length ? String(start + size) : \"\" });\n },\n };\n}\n\nconst PIPELINE_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,80}$/;\n\n/**\n * Pipelines a person approved, as one JSON file each in a folder\n * (`<id>.json`, every version in it), so they are reviewed and committed like\n * other project files. Only the runner writes here, after its checks.\n */\nexport function filePipelineStore(dir: string): PipelineStore {\n return {\n async list() {\n if (!fs.existsSync(dir)) return [];\n return fs\n .readdirSync(dir)\n .filter((f) => f.endsWith(\".json\") && PIPELINE_ID.test(f.slice(0, -5)))\n .flatMap((file) => {\n try {\n const saved = JSON.parse(fs.readFileSync(path.join(dir, file), \"utf8\")) as SavedPipeline;\n return saved?.definition?.id === file.slice(0, -5) ? [saved] : [];\n } catch {\n // A file that does not parse is left alone and not offered.\n return [];\n }\n });\n },\n async put(saved) {\n if (!PIPELINE_ID.test(saved.definition.id)) throw new Error(`Not a pipeline ID: ${saved.definition.id}`);\n fs.mkdirSync(dir, { recursive: true });\n fs.writeFileSync(path.join(dir, `${saved.definition.id}.json`), `${JSON.stringify(saved, null, 2)}\\n`);\n },\n };\n}\n\n/**\n * Runs kept as one JSON file per pipeline in a folder, newest first and at\n * most `limit` of them, so history outlives a restart. A run is written as it\n * changes; the last write wins, so one server should own a folder.\n */\nexport function fileRunStore(dir: string, limit = 50): RunStore {\n const fileOf = (pipelineId: string) => path.join(dir, `${pipelineId}.json`);\n const read = (file: string): Run[] => {\n try {\n return (JSON.parse(fs.readFileSync(file, \"utf8\")) as unknown[]).map((run) => fromJson(RunSchema, run as never, { ignoreUnknownFields: true }));\n } catch {\n return [];\n }\n };\n return {\n async load() {\n if (!fs.existsSync(dir)) return [];\n return fs\n .readdirSync(dir)\n .filter((f) => f.endsWith(\".json\"))\n .flatMap((f) => read(path.join(dir, f)))\n .sort((a, b) => b.startTime.localeCompare(a.startTime));\n },\n async save(run) {\n if (!PIPELINE_ID.test(run.pipelineId)) return;\n const file = fileOf(run.pipelineId);\n const runs = fs.existsSync(file) ? read(file) : [];\n const index = runs.findIndex((r) => r.id === run.id);\n if (index >= 0) runs[index] = run;\n else runs.unshift(run);\n fs.mkdirSync(dir, { recursive: true });\n fs.writeFileSync(file, `${JSON.stringify(runs.slice(0, limit).map((r) => toJson(RunSchema, r)), null, 1)}\\n`);\n },\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surfaces-ui/dev-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Local Connect server for Surfaces UI data sources",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"surfaces-ui",
|
|
7
|
+
"analytics",
|
|
8
|
+
"data",
|
|
9
|
+
"server",
|
|
10
|
+
"connect",
|
|
11
|
+
"duckdb",
|
|
12
|
+
"teradata"
|
|
13
|
+
],
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/teradata-labs/surfaces-ui.git",
|
|
18
|
+
"directory": "packages/dev-server"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/teradata-labs/surfaces-ui#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/teradata-labs/surfaces-ui/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"NOTICE"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@bufbuild/protobuf": "^2.17.0",
|
|
39
|
+
"@connectrpc/connect": "^2.3.0",
|
|
40
|
+
"@connectrpc/connect-node": "^2.3.0",
|
|
41
|
+
"apache-arrow": "^21.2.0",
|
|
42
|
+
"@surfaces-ui/agent": "0.2.0",
|
|
43
|
+
"@surfaces-ui/data": "0.2.0",
|
|
44
|
+
"@surfaces-ui/discovery": "0.2.0",
|
|
45
|
+
"@surfaces-ui/engine": "0.2.0",
|
|
46
|
+
"@surfaces-ui/engine-datafusion": "0.2.0",
|
|
47
|
+
"@surfaces-ui/engine-duckdb": "0.2.0",
|
|
48
|
+
"@surfaces-ui/engine-teradata": "0.2.0",
|
|
49
|
+
"@surfaces-ui/pipelines": "0.2.0",
|
|
50
|
+
"@surfaces-ui/engine-service": "0.2.0",
|
|
51
|
+
"@surfaces-ui/pipelines-dbt": "0.2.0",
|
|
52
|
+
"@surfaces-ui/proto": "0.2.0",
|
|
53
|
+
"@surfaces-ui/sql": "0.2.0",
|
|
54
|
+
"@surfaces-ui/seeds": "0.2.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^26.6.6",
|
|
58
|
+
"@surfaces-ui/client-connect": "0.2.0"
|
|
59
|
+
},
|
|
60
|
+
"bin": {
|
|
61
|
+
"surfaces-dev": "./dist/cli.js",
|
|
62
|
+
"surfaces-pipelines": "./dist/pipelines-cli.js"
|
|
63
|
+
},
|
|
64
|
+
"optionalDependencies": {
|
|
65
|
+
"@surfaces-ui/embedder-local": "0.2.0"
|
|
66
|
+
},
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public",
|
|
69
|
+
"provenance": true
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "tsc -p tsconfig.build.json",
|
|
73
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
74
|
+
"test": "vitest run --passWithNoTests"
|
|
75
|
+
}
|
|
6
76
|
}
|