@haverstack/commons 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.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
2
+
3
+ To the extent possible under law, the Haverstack contributors have waived all
4
+ copyright and related or neighboring rights to Haverstack. This work is
5
+ published from the United States.
6
+
7
+ https://creativecommons.org/publicdomain/zero/1.0/
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # @haverstack/commons
2
+
3
+ Canonical [Schema Commons](https://github.com/haverstack/core/tree/main/docs/commons)
4
+ type definitions for Haverstack.
5
+
6
+ The commons namespace `org.haverstack` is reserved for a small set of well-known,
7
+ neutrally-governed types (`note`, `bookmark`, `task`, ...) so that apps sharing a stack
8
+ can interoperate on the data shapes almost every personal app touches. That only works
9
+ if every app registers a commons type **exactly as written** — a modified copy under
10
+ the same `typeId` is schema drift, and the drift guard will (correctly) reject it. This
11
+ package makes that structural rather than social: import the constant, don't
12
+ hand-transcribe a schema out of markdown.
13
+
14
+ > **Status:** Early development. Exports only Draft-status types — see
15
+ > [`docs/commons/README.md`](https://github.com/haverstack/core/blob/main/docs/commons/README.md)
16
+ > for what Draft/Staged/Proposed mean. Proposed types have no intended writer yet and
17
+ > stay docs-only until they graduate.
18
+
19
+ ## Installation
20
+
21
+ ```sh
22
+ npm install @haverstack/commons
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ts
28
+ import { Stack } from '@haverstack/core';
29
+ import { defineCommonsTypes, NOTE, TASK } from '@haverstack/commons';
30
+
31
+ // Register only the commons types your app actually writes.
32
+ await defineCommonsTypes(stack, [NOTE, TASK]);
33
+
34
+ const note = await stack.create(NOTE.id, { text: 'Hello, Haverstack!' });
35
+ ```
36
+
37
+ Each export (`NOTE`, `BOOKMARK`, `TASK`, `CONTACT`, `ARTICLE`, `PLACE`, `PAGE`, `PHOTO`)
38
+ is a `{ id, name, schema }` triple mirroring its type's `stack.defineType(...)` block in
39
+ [`docs/commons/`](https://github.com/haverstack/core/tree/main/docs/commons) exactly.
40
+ `defineCommonsTypes()` is a thin loop over `stack.defineType()` — calling it again with
41
+ types already registered is the ordinary idempotent no-op path (see `defineType`'s own
42
+ docs), so it's safe to call on every app startup.
43
+
44
+ ## Governance
45
+
46
+ The schemas here are not this package's to change. A type's shape, required core, and
47
+ conventions are decided by the process in
48
+ [`docs/commons/README.md` § Governance](https://github.com/haverstack/core/blob/main/docs/commons/README.md#governance) —
49
+ propose additions or changes there, as an issue on `haverstack/core` titled
50
+ `Commons: <proposal>`. This package's constants are updated to match once a proposal
51
+ lands; it never carries a schema the docs don't also carry.
52
+
53
+ ## License
54
+
55
+ [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/) — public domain.
56
+
57
+ ## Monorepo
58
+
59
+ Part of [haverstack/core](https://github.com/haverstack/core).
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @haverstack/commons
3
+ * -------------------------------------------------------
4
+ * Canonical Schema Commons type definitions — see docs/commons/README.md for
5
+ * the design rules and governance process these schemas are bound by.
6
+ *
7
+ * Each export mirrors the fenced `stack.defineType(...)` block in its type's
8
+ * doc file exactly. Apps register commons types by passing these constants
9
+ * to `defineCommonsTypes()` rather than hand-copying schemas out of
10
+ * markdown, which is the drift the Schema Commons' governance process exists
11
+ * to prevent.
12
+ *
13
+ * Only Draft-status types are exported here. Proposed types (not yet backed
14
+ * by a concrete intended writer) stay docs-only until they graduate.
15
+ */
16
+ import type { Stack, StackType, TypeId, TypeSchema } from '@haverstack/core';
17
+ export type CommonsType = {
18
+ readonly id: TypeId;
19
+ readonly name: string;
20
+ readonly schema: TypeSchema;
21
+ };
22
+ export declare const NOTE: CommonsType;
23
+ export declare const BOOKMARK: CommonsType;
24
+ export declare const TASK: CommonsType;
25
+ export declare const CONTACT: CommonsType;
26
+ export declare const ARTICLE: CommonsType;
27
+ export declare const PLACE: CommonsType;
28
+ export declare const PAGE: CommonsType;
29
+ export declare const PHOTO: CommonsType;
30
+ /**
31
+ * Registers each given commons type on `stack` via `defineType()`, exactly
32
+ * as written here. Sequential, matching `Stack`'s own system-type seeding —
33
+ * each call is independent, but running in order keeps the returned array
34
+ * predictable.
35
+ */
36
+ export declare const defineCommonsTypes: (stack: Stack, types: readonly CommonsType[]) => Promise<StackType[]>;
37
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE7E,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;CAC7B,CAAC;AAUF,eAAO,MAAM,IAAI,EAAE,WAQlB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,WAQtB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,WAUlB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,WAWrB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,WAYrB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,WAUnB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,WAkBlB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,WASnB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAC7B,OAAO,KAAK,EACZ,OAAO,SAAS,WAAW,EAAE,KAC5B,OAAO,CAAC,SAAS,EAAE,CAMrB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @haverstack/commons
3
+ * -------------------------------------------------------
4
+ * Canonical Schema Commons type definitions — see docs/commons/README.md for
5
+ * the design rules and governance process these schemas are bound by.
6
+ *
7
+ * Each export mirrors the fenced `stack.defineType(...)` block in its type's
8
+ * doc file exactly. Apps register commons types by passing these constants
9
+ * to `defineCommonsTypes()` rather than hand-copying schemas out of
10
+ * markdown, which is the drift the Schema Commons' governance process exists
11
+ * to prevent.
12
+ *
13
+ * Only Draft-status types are exported here. Proposed types (not yet backed
14
+ * by a concrete intended writer) stay docs-only until they graduate.
15
+ */
16
+ const labeledValue = {
17
+ kind: 'object',
18
+ properties: {
19
+ value: { kind: 'string', required: true },
20
+ label: { kind: 'string' },
21
+ },
22
+ };
23
+ export const NOTE = {
24
+ id: 'org.haverstack/note@1',
25
+ name: 'Note',
26
+ schema: {
27
+ text: { kind: 'text', required: true },
28
+ title: { kind: 'string' },
29
+ format: { kind: 'string' },
30
+ },
31
+ };
32
+ export const BOOKMARK = {
33
+ id: 'org.haverstack/bookmark@1',
34
+ name: 'Bookmark',
35
+ schema: {
36
+ url: { kind: 'string', required: true },
37
+ title: { kind: 'string' },
38
+ description: { kind: 'text' },
39
+ },
40
+ };
41
+ export const TASK = {
42
+ id: 'org.haverstack/task@1',
43
+ name: 'Task',
44
+ schema: {
45
+ title: { kind: 'string', required: true },
46
+ done: { kind: 'boolean', required: true },
47
+ notes: { kind: 'text' },
48
+ due: { kind: 'date' },
49
+ completedAt: { kind: 'date' },
50
+ },
51
+ };
52
+ export const CONTACT = {
53
+ id: 'org.haverstack/contact@1',
54
+ name: 'Contact',
55
+ schema: {
56
+ name: { kind: 'string', required: true },
57
+ emails: { kind: 'array', items: labeledValue },
58
+ phones: { kind: 'array', items: labeledValue },
59
+ urls: { kind: 'array', items: labeledValue },
60
+ org: { kind: 'string' },
61
+ note: { kind: 'text' },
62
+ },
63
+ };
64
+ export const ARTICLE = {
65
+ id: 'org.haverstack/article@1',
66
+ name: 'Article',
67
+ schema: {
68
+ title: { kind: 'string', required: true },
69
+ text: { kind: 'text', required: true },
70
+ format: { kind: 'string' },
71
+ summary: { kind: 'text' },
72
+ url: { kind: 'string' },
73
+ author: { kind: 'string' },
74
+ publishedAt: { kind: 'date' },
75
+ },
76
+ };
77
+ export const PLACE = {
78
+ id: 'org.haverstack/place@1',
79
+ name: 'Place',
80
+ schema: {
81
+ latitude: { kind: 'number', required: true },
82
+ longitude: { kind: 'number', required: true },
83
+ name: { kind: 'string' },
84
+ address: { kind: 'string' },
85
+ url: { kind: 'string' },
86
+ },
87
+ };
88
+ export const PAGE = {
89
+ id: 'org.haverstack/page@1',
90
+ name: 'Page',
91
+ schema: {
92
+ slug: { kind: 'string', required: true },
93
+ text: { kind: 'text', required: true },
94
+ title: { kind: 'string' },
95
+ format: { kind: 'string' },
96
+ publishedAt: { kind: 'date' },
97
+ collection: {
98
+ kind: 'object',
99
+ properties: {
100
+ typeId: { kind: 'string', required: true },
101
+ tag: { kind: 'string' },
102
+ order: { kind: 'string' },
103
+ },
104
+ },
105
+ },
106
+ };
107
+ export const PHOTO = {
108
+ id: 'org.haverstack/photo@1',
109
+ name: 'Photo',
110
+ schema: {
111
+ image: { kind: 'file-ref', required: true },
112
+ caption: { kind: 'text' },
113
+ alt: { kind: 'string' },
114
+ takenAt: { kind: 'date' },
115
+ },
116
+ };
117
+ /**
118
+ * Registers each given commons type on `stack` via `defineType()`, exactly
119
+ * as written here. Sequential, matching `Stack`'s own system-type seeding —
120
+ * each call is independent, but running in order keeps the returned array
121
+ * predictable.
122
+ */
123
+ export const defineCommonsTypes = async (stack, types) => {
124
+ const defined = [];
125
+ for (const type of types) {
126
+ defined.push(await stack.defineType(type.id, type.name, type.schema));
127
+ }
128
+ return defined;
129
+ };
130
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAUH,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,KAAK,EAAE,EAAE,IAAI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M,OAAO,GAAgB,EAAE,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@haverstack/commons",
3
+ "version": "0.1.0",
4
+ "description": "Canonical Schema Commons type definitions for Haverstack — register commons types exactly as written",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "types": "./dist/index.d.ts"
10
+ }
11
+ },
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/haverstack/core",
20
+ "directory": "packages/commons"
21
+ },
22
+ "license": "CC0-1.0",
23
+ "keywords": [
24
+ "haverstack",
25
+ "personal data",
26
+ "schema commons",
27
+ "interop"
28
+ ],
29
+ "dependencies": {
30
+ "@haverstack/core": "^0.9.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^22.0.0",
34
+ "typescript": "^5.5.0",
35
+ "vitest": "^2.0.0"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.build.json",
39
+ "test": "vitest run",
40
+ "typecheck": "tsc --noEmit",
41
+ "lint": "eslint src tests"
42
+ }
43
+ }