@legioncodeinc/nectar 0.0.1 → 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.md +662 -662
- package/README.md +307 -307
- package/dist/brooding/describe.js +13 -13
- package/dist/cli.js +26 -26
- package/dist/service/templates.js +80 -80
- package/dist/telemetry/checkin.js +6 -6
- package/dist/telemetry/db.js +21 -21
- package/dist/telemetry/metrics.js +8 -8
- package/dist/telemetry-usage/posthog-key.js +4 -22
- package/package.json +48 -44
- package/dist/embeddings/cohere-portkey.d.ts +0 -67
- package/dist/embeddings/cohere-portkey.d.ts.map +0 -1
- package/dist/embeddings/cohere-portkey.js +0 -171
- package/dist/embeddings/cohere-portkey.js.map +0 -1
- package/dist/hivedoctor-registry.d.ts +0 -111
- package/dist/hivedoctor-registry.d.ts.map +0 -1
- package/dist/hivedoctor-registry.js +0 -143
- package/dist/hivedoctor-registry.js.map +0 -1
- package/dist/source-graph/deeplake-credentials.d.ts +0 -57
- package/dist/source-graph/deeplake-credentials.d.ts.map +0 -1
- package/dist/source-graph/deeplake-credentials.js +0 -109
- package/dist/source-graph/deeplake-credentials.js.map +0 -1
- package/dist/source-graph/deeplake-heal.d.ts +0 -53
- package/dist/source-graph/deeplake-heal.d.ts.map +0 -1
- package/dist/source-graph/deeplake-heal.js +0 -41
- package/dist/source-graph/deeplake-heal.js.map +0 -1
- package/dist/source-graph/deeplake-store.d.ts +0 -151
- package/dist/source-graph/deeplake-store.d.ts.map +0 -1
- package/dist/source-graph/deeplake-store.js +0 -389
- package/dist/source-graph/deeplake-store.js.map +0 -1
- package/dist/source-graph/deeplake-transport.d.ts +0 -74
- package/dist/source-graph/deeplake-transport.d.ts.map +0 -1
- package/dist/source-graph/deeplake-transport.js +0 -107
- package/dist/source-graph/deeplake-transport.js.map +0 -1
- package/dist/source-graph/hash.d.ts +0 -3
- package/dist/source-graph/hash.d.ts.map +0 -1
- package/dist/source-graph/hash.js +0 -12
- package/dist/source-graph/hash.js.map +0 -1
- package/dist/source-graph/memory-store.d.ts +0 -32
- package/dist/source-graph/memory-store.d.ts.map +0 -1
- package/dist/source-graph/memory-store.js +0 -81
- package/dist/source-graph/memory-store.js.map +0 -1
- package/dist/source-graph/model.d.ts +0 -102
- package/dist/source-graph/model.d.ts.map +0 -1
- package/dist/source-graph/model.js +0 -36
- package/dist/source-graph/model.js.map +0 -1
- package/dist/source-graph/paths.d.ts +0 -7
- package/dist/source-graph/paths.d.ts.map +0 -1
- package/dist/source-graph/paths.js +0 -26
- package/dist/source-graph/paths.js.map +0 -1
- package/dist/source-graph/schema.d.ts +0 -44
- package/dist/source-graph/schema.d.ts.map +0 -1
- package/dist/source-graph/schema.js +0 -123
- package/dist/source-graph/schema.js.map +0 -1
- package/dist/source-graph/sql-guards.d.ts +0 -99
- package/dist/source-graph/sql-guards.d.ts.map +0 -1
- package/dist/source-graph/sql-guards.js +0 -129
- package/dist/source-graph/sql-guards.js.map +0 -1
- package/dist/source-graph/store.d.ts +0 -101
- package/dist/source-graph/store.d.ts.map +0 -1
- package/dist/source-graph/store.js +0 -2
- package/dist/source-graph/store.js.map +0 -1
- package/dist/source-graph/ulid.d.ts +0 -9
- package/dist/source-graph/ulid.d.ts.map +0 -1
- package/dist/source-graph/ulid.js +0 -61
- package/dist/source-graph/ulid.js.map +0 -1
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Source Graph table definitions (PRD-005), transcribed from the DDL in
|
|
3
|
-
* `library/knowledge/private/data/source-graph-schema.md`.
|
|
4
|
-
*
|
|
5
|
-
* These `ColumnDef[]` arrays are the catalog contract the Deep Lake adapter
|
|
6
|
-
* (`deeplake-store.ts`) registers (mirroring honeycomb's `CatalogTable` /
|
|
7
|
-
* `ColumnDef` and its load-time guard: valid identifiers, no duplicates, and
|
|
8
|
-
* every NOT NULL column carries a DEFAULT, except the nullable
|
|
9
|
-
* `embedding`/`confidence`/`fingerprint`). Both tables self-create on first write via
|
|
10
|
-
* `deeplake-heal.ts`'s `withHeal`; there is no DDL pre-step.
|
|
11
|
-
*/
|
|
12
|
-
import { sqlIdent, sqlStr } from "./sql-guards.js";
|
|
13
|
-
/** `source_graph` (identity + provenance). All TEXT NOT NULL with defaults; `kind` defaults to 'file'. */
|
|
14
|
-
export const SOURCE_GRAPH_COLUMNS = [
|
|
15
|
-
{ name: "nectar", type: "TEXT", notNull: true, default: "" },
|
|
16
|
-
{ name: "kind", type: "TEXT", notNull: true, default: "file" },
|
|
17
|
-
{ name: "created_at", type: "TEXT", notNull: true, default: "" },
|
|
18
|
-
{ name: "derived_from_nectar", type: "TEXT", notNull: true, default: "" },
|
|
19
|
-
{ name: "fork_content_hash", type: "TEXT", notNull: true, default: "" },
|
|
20
|
-
{ name: "org_id", type: "TEXT", notNull: true, default: "" },
|
|
21
|
-
{ name: "workspace_id", type: "TEXT", notNull: true, default: "" },
|
|
22
|
-
{ name: "project_id", type: "TEXT", notNull: true, default: "" },
|
|
23
|
-
{ name: "last_update_date", type: "TEXT", notNull: true, default: "" },
|
|
24
|
-
];
|
|
25
|
-
/** `source_graph_versions` (content + description chain). `embedding` + `confidence` + `fingerprint` are nullable. */
|
|
26
|
-
export const SOURCE_GRAPH_VERSIONS_COLUMNS = [
|
|
27
|
-
{ name: "nectar", type: "TEXT", notNull: true, default: "" },
|
|
28
|
-
{ name: "content_hash", type: "TEXT", notNull: true, default: "" },
|
|
29
|
-
{ name: "seq", type: "BIGINT", notNull: true, default: 0 },
|
|
30
|
-
{ name: "path", type: "TEXT", notNull: true, default: "" },
|
|
31
|
-
{ name: "filename", type: "TEXT", notNull: true, default: "" },
|
|
32
|
-
{ name: "ext", type: "TEXT", notNull: true, default: "" },
|
|
33
|
-
{ name: "size_bytes", type: "BIGINT", notNull: true, default: 0 },
|
|
34
|
-
{ name: "mtime_observed", type: "TEXT", notNull: true, default: "" },
|
|
35
|
-
{ name: "title", type: "TEXT", notNull: true, default: "" },
|
|
36
|
-
{ name: "description", type: "TEXT", notNull: true, default: "" },
|
|
37
|
-
{ name: "concepts", type: "TEXT", notNull: true, default: "[]" },
|
|
38
|
-
{ name: "embedding", type: "FLOAT4[]", notNull: false },
|
|
39
|
-
{ name: "confidence", type: "REAL", notNull: false },
|
|
40
|
-
{ name: "fingerprint", type: "TEXT", notNull: false },
|
|
41
|
-
{ name: "described_at", type: "TEXT", notNull: true, default: "" },
|
|
42
|
-
{ name: "describe_model", type: "TEXT", notNull: true, default: "" },
|
|
43
|
-
{ name: "describe_status", type: "TEXT", notNull: true, default: "pending" },
|
|
44
|
-
{ name: "observed_at", type: "TEXT", notNull: true, default: "" },
|
|
45
|
-
{ name: "org_id", type: "TEXT", notNull: true, default: "" },
|
|
46
|
-
{ name: "workspace_id", type: "TEXT", notNull: true, default: "" },
|
|
47
|
-
{ name: "project_id", type: "TEXT", notNull: true, default: "" },
|
|
48
|
-
{ name: "last_update_date", type: "TEXT", notNull: true, default: "" },
|
|
49
|
-
];
|
|
50
|
-
export const SOURCE_GRAPH_TABLE = {
|
|
51
|
-
name: "source_graph",
|
|
52
|
-
scope: "tenant",
|
|
53
|
-
writePattern: "update-or-insert",
|
|
54
|
-
columns: SOURCE_GRAPH_COLUMNS,
|
|
55
|
-
};
|
|
56
|
-
export const SOURCE_GRAPH_VERSIONS_TABLE = {
|
|
57
|
-
name: "source_graph_versions",
|
|
58
|
-
scope: "tenant",
|
|
59
|
-
writePattern: "append-only",
|
|
60
|
-
columns: SOURCE_GRAPH_VERSIONS_COLUMNS,
|
|
61
|
-
};
|
|
62
|
-
/** The `source-graph` catalog group appended to the daemon's CATALOG aggregation. */
|
|
63
|
-
export const SOURCE_GRAPH_CATALOG_GROUP = {
|
|
64
|
-
name: "source-graph",
|
|
65
|
-
tables: [SOURCE_GRAPH_TABLE, SOURCE_GRAPH_VERSIONS_TABLE],
|
|
66
|
-
};
|
|
67
|
-
const IDENT_RE = /^[a-z_][a-z0-9_]*$/;
|
|
68
|
-
/**
|
|
69
|
-
* The load-time guard (mirrors honeycomb `schema.ts:80-100`): valid identifiers,
|
|
70
|
-
* no duplicate columns, and every NOT NULL column carries a DEFAULT. Throws on
|
|
71
|
-
* violation. Returns the table unchanged so it can wrap a definition inline.
|
|
72
|
-
*/
|
|
73
|
-
export function assertValidCatalogTable(table) {
|
|
74
|
-
if (!IDENT_RE.test(table.name)) {
|
|
75
|
-
throw new Error(`invalid table name: ${table.name}`);
|
|
76
|
-
}
|
|
77
|
-
const seen = new Set();
|
|
78
|
-
for (const col of table.columns) {
|
|
79
|
-
if (!IDENT_RE.test(col.name)) {
|
|
80
|
-
throw new Error(`invalid column identifier: ${table.name}.${col.name}`);
|
|
81
|
-
}
|
|
82
|
-
if (seen.has(col.name)) {
|
|
83
|
-
throw new Error(`duplicate column: ${table.name}.${col.name}`);
|
|
84
|
-
}
|
|
85
|
-
seen.add(col.name);
|
|
86
|
-
if (col.notNull && col.default === undefined) {
|
|
87
|
-
throw new Error(`NOT NULL column without DEFAULT: ${table.name}.${col.name}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return table;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Render one column's SQL clause (`<name> <type>[ NOT NULL][ DEFAULT <lit>]`)
|
|
94
|
-
* from a `ColumnDef`. The identifier is validated through `sqlIdent`; a
|
|
95
|
-
* string `default` is rendered as a quoted literal via `sqlStr` (the TEXT
|
|
96
|
-
* columns' defaults, e.g. `''`, `'file'`, `'[]'`, `'pending'`), a numeric
|
|
97
|
-
* `default` is inlined bare (the BIGINT columns' `0`). `FLOAT4[]`/`REAL`
|
|
98
|
-
* columns in this catalog are always nullable and carry no default.
|
|
99
|
-
*/
|
|
100
|
-
function columnClause(col) {
|
|
101
|
-
const name = sqlIdent(col.name);
|
|
102
|
-
const notNull = col.notNull ? " NOT NULL" : "";
|
|
103
|
-
let defaultClause = "";
|
|
104
|
-
if (col.default !== undefined) {
|
|
105
|
-
defaultClause = typeof col.default === "number" ? ` DEFAULT ${col.default}` : ` DEFAULT '${sqlStr(col.default)}'`;
|
|
106
|
-
}
|
|
107
|
-
return `${name} ${col.type}${notNull}${defaultClause}`;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Render `CREATE TABLE IF NOT EXISTS "<name>" (...) USING deeplake` from a
|
|
111
|
-
* `CatalogTable`, mirroring honeycomb's `buildCreateTableSql`
|
|
112
|
-
* (`src/daemon/storage/schema.ts:110-114`). `IF NOT EXISTS` is what makes two
|
|
113
|
-
* concurrent healers converge: the second create is a harmless no-op, not a
|
|
114
|
-
* duplicate-table error. The table name is validated through `sqlIdent`;
|
|
115
|
-
* column names are validated at load by `assertValidCatalogTable`, so they are
|
|
116
|
-
* safe to interpolate via {@link columnClause}.
|
|
117
|
-
*/
|
|
118
|
-
export function buildCreateTableSql(table) {
|
|
119
|
-
const safeName = sqlIdent(table.name);
|
|
120
|
-
const colSql = table.columns.map(columnClause).join(", ");
|
|
121
|
-
return `CREATE TABLE IF NOT EXISTS "${safeName}" (${colSql}) USING deeplake`;
|
|
122
|
-
}
|
|
123
|
-
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/source-graph/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAqBnD,0GAA0G;AAC1G,MAAM,CAAC,MAAM,oBAAoB,GAAyB;IACxD,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;IAC5D,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE;IAC9D,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IA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CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,aAAa,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;IACpH,CAAC;IACD,OAAO,GAAG,IAAI,IAAI,GAAG,CAAC,IAAI,GAAG,OAAO,GAAG,aAAa,EAAE,CAAC;AACzD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAmB;IACrD,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1D,OAAO,+BAA+B,QAAQ,MAAM,MAAM,kBAAkB,CAAC;AAC/E,CAAC"}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQL-safety escaping helpers for the Deep Lake adapter (PRD-005).
|
|
3
|
-
*
|
|
4
|
-
* Ported (not imported) from honeycomb's `src/daemon/storage/sql.ts`, per
|
|
5
|
-
* ADR-0002: hivenectar reaches Deep Lake over the network through its own
|
|
6
|
-
* client and never imports the honeycomb runtime in-process, so the escaping
|
|
7
|
-
* floor is mirrored here rather than shared across the process boundary.
|
|
8
|
-
*
|
|
9
|
-
* The Deep Lake HTTP query endpoint binds no parameters: every value is
|
|
10
|
-
* escaped and interpolated into the statement by hand before it is sent.
|
|
11
|
-
* There is no parameterized fallback to forget to use, so these helpers ARE
|
|
12
|
-
* the parameter binding. Every dynamic value the Deep Lake adapter builds
|
|
13
|
-
* (`schema.ts`'s `buildCreateTableSql`, `deeplake-store.ts`'s query builders)
|
|
14
|
-
* routes through `sqlStr` / `sqlLike` / `sqlIdent` / `sLiteral` / `eLiteral`.
|
|
15
|
-
*
|
|
16
|
-
* These functions are pure, synchronous, side-effect-free, and dependency-free
|
|
17
|
-
* beyond the language runtime (hivenectar's zero-runtime-dependency rule).
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* Escape a string for use inside a single-quoted SQL literal.
|
|
21
|
-
*
|
|
22
|
-
* Order matters: backslashes are doubled FIRST (so the backslash added for a
|
|
23
|
-
* doubled quote is not itself re-escaped), then single quotes are doubled,
|
|
24
|
-
* then NUL and the C0/C1 control characters are dropped. The result is the
|
|
25
|
-
* inner body of the literal; the caller wraps it in quotes (`'${sqlStr(v)}'`,
|
|
26
|
-
* or via {@link sLiteral}) or uses the `E'...'` form via {@link eLiteral} when
|
|
27
|
-
* the body carries escape sequences.
|
|
28
|
-
*
|
|
29
|
-
* Because every quote is doubled and every backslash is doubled, an injection
|
|
30
|
-
* payload like `'; DROP TABLE x; --` collapses to one inert literal: the
|
|
31
|
-
* embedded quote can never close the string early, so no second statement is
|
|
32
|
-
* ever produced.
|
|
33
|
-
*/
|
|
34
|
-
export declare function sqlStr(value: string): string;
|
|
35
|
-
/**
|
|
36
|
-
* Escape a string for use inside a `LIKE` / `ILIKE` pattern.
|
|
37
|
-
*
|
|
38
|
-
* Escapes the `LIKE` metacharacters (`%` and `_`) so a literal substring
|
|
39
|
-
* search is never reinterpreted as a wildcard match, alongside the same
|
|
40
|
-
* quote-doubling and control stripping {@link sqlStr} performs. Not currently
|
|
41
|
-
* exercised by the source-graph store's equality-only reads, but ported
|
|
42
|
-
* alongside `sqlStr`/`sqlIdent` so a future prefix/substring query never has
|
|
43
|
-
* to reach for a hand-rolled escape.
|
|
44
|
-
*/
|
|
45
|
-
export declare function sqlLike(value: string): string;
|
|
46
|
-
/**
|
|
47
|
-
* Validate a table/column identifier against `^[a-zA-Z_][a-zA-Z0-9_]*$`.
|
|
48
|
-
* Returns the name UNCHANGED on success; throws on anything else.
|
|
49
|
-
*
|
|
50
|
-
* Strict by design: it THROWS rather than sanitizing, because a silently
|
|
51
|
-
* rewritten identifier would be a worse, harder-to-debug failure than a
|
|
52
|
-
* rejected one. Callers pass only known schema names (table and column
|
|
53
|
-
* identifiers from `SOURCE_GRAPH_COLUMNS` / `SOURCE_GRAPH_VERSIONS_COLUMNS`),
|
|
54
|
-
* so a rejection is always a programmer error worth surfacing.
|
|
55
|
-
*/
|
|
56
|
-
export declare function sqlIdent(name: string): string;
|
|
57
|
-
/**
|
|
58
|
-
* Build an ordinary single-quoted literal from a value. Thin convenience
|
|
59
|
-
* around `'${sqlStr(v)}'` so call sites read as a builder call rather than raw
|
|
60
|
-
* quote assembly. Use for ids, paths, hashes, enum-like values, and dates.
|
|
61
|
-
* Use {@link eLiteral} instead when the body may carry escape sequences
|
|
62
|
-
* (free-text title/description/concepts).
|
|
63
|
-
*/
|
|
64
|
-
export declare function sLiteral(value: string): string;
|
|
65
|
-
/**
|
|
66
|
-
* Build an `E'...'` escape-string literal from a raw text body.
|
|
67
|
-
*
|
|
68
|
-
* Free-text bodies that may contain escape sequences (a description or title
|
|
69
|
-
* with a literal backslash) must use the `E'...'` form so the
|
|
70
|
-
* doubled-backslash escaping from {@link sqlStr} round-trips to the intended
|
|
71
|
-
* bytes; a plain `'...'` literal for a body with backslashes would corrupt it.
|
|
72
|
-
*/
|
|
73
|
-
export declare function eLiteral(body: string): string;
|
|
74
|
-
/**
|
|
75
|
-
* Validate and render a numeric value for bare (unquoted) SQL interpolation.
|
|
76
|
-
* Throws unless `value` is, at runtime, a finite JavaScript `number` -
|
|
77
|
-
* TypeScript's `number` type is erased at runtime, so a value that merely
|
|
78
|
-
* carries the `number` type at compile time (e.g. `row.seq`, `row.sizeBytes`,
|
|
79
|
-
* `row.confidence`, or one entry of an embedding vector) is not actually
|
|
80
|
-
* guaranteed to be a safe, quote-free numeric literal unless this is checked
|
|
81
|
-
* here. Without this guard, a non-numeric value smuggled past the type
|
|
82
|
-
* system (a string, `NaN`, `Infinity`, or an object) would be interpolated
|
|
83
|
-
* bare via `String(value)` with no escaping at all - the same injection
|
|
84
|
-
* shape `sqlStr`/`sqlIdent` close for text and identifiers, just for the
|
|
85
|
-
* numeric case. Rejects `NaN`/`Infinity`/`-Infinity` too, since those are not
|
|
86
|
-
* valid bare-numeric SQL tokens.
|
|
87
|
-
*/
|
|
88
|
-
export declare function sqlNum(value: number): string;
|
|
89
|
-
/**
|
|
90
|
-
* Serialize a `number[]` to a `FLOAT4[]` SQL literal (`ARRAY[...]::float4[]`),
|
|
91
|
-
* mirroring honeycomb's `serializeFloat4Array` (`src/daemon/storage/vector.ts`).
|
|
92
|
-
* Every entry is validated via {@link sqlNum} before interpolation - the
|
|
93
|
-
* dimension contract (`isValidEmbedding`, 768) is a separate application-level
|
|
94
|
-
* check the caller is still responsible for, but this function does not rely
|
|
95
|
-
* on the caller to have validated *finiteness*: a non-numeric or non-finite
|
|
96
|
-
* entry throws here rather than being interpolated bare into the statement.
|
|
97
|
-
*/
|
|
98
|
-
export declare function sqlFloat4Array(vector: readonly number[]): string;
|
|
99
|
-
//# sourceMappingURL=sql-guards.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sql-guards.d.ts","sourceRoot":"","sources":["../../src/source-graph/sql-guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAO5C;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM7C;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK7C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAGhE"}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SQL-safety escaping helpers for the Deep Lake adapter (PRD-005).
|
|
3
|
-
*
|
|
4
|
-
* Ported (not imported) from honeycomb's `src/daemon/storage/sql.ts`, per
|
|
5
|
-
* ADR-0002: hivenectar reaches Deep Lake over the network through its own
|
|
6
|
-
* client and never imports the honeycomb runtime in-process, so the escaping
|
|
7
|
-
* floor is mirrored here rather than shared across the process boundary.
|
|
8
|
-
*
|
|
9
|
-
* The Deep Lake HTTP query endpoint binds no parameters: every value is
|
|
10
|
-
* escaped and interpolated into the statement by hand before it is sent.
|
|
11
|
-
* There is no parameterized fallback to forget to use, so these helpers ARE
|
|
12
|
-
* the parameter binding. Every dynamic value the Deep Lake adapter builds
|
|
13
|
-
* (`schema.ts`'s `buildCreateTableSql`, `deeplake-store.ts`'s query builders)
|
|
14
|
-
* routes through `sqlStr` / `sqlLike` / `sqlIdent` / `sLiteral` / `eLiteral`.
|
|
15
|
-
*
|
|
16
|
-
* These functions are pure, synchronous, side-effect-free, and dependency-free
|
|
17
|
-
* beyond the language runtime (hivenectar's zero-runtime-dependency rule).
|
|
18
|
-
*/
|
|
19
|
-
/**
|
|
20
|
-
* Escape a string for use inside a single-quoted SQL literal.
|
|
21
|
-
*
|
|
22
|
-
* Order matters: backslashes are doubled FIRST (so the backslash added for a
|
|
23
|
-
* doubled quote is not itself re-escaped), then single quotes are doubled,
|
|
24
|
-
* then NUL and the C0/C1 control characters are dropped. The result is the
|
|
25
|
-
* inner body of the literal; the caller wraps it in quotes (`'${sqlStr(v)}'`,
|
|
26
|
-
* or via {@link sLiteral}) or uses the `E'...'` form via {@link eLiteral} when
|
|
27
|
-
* the body carries escape sequences.
|
|
28
|
-
*
|
|
29
|
-
* Because every quote is doubled and every backslash is doubled, an injection
|
|
30
|
-
* payload like `'; DROP TABLE x; --` collapses to one inert literal: the
|
|
31
|
-
* embedded quote can never close the string early, so no second statement is
|
|
32
|
-
* ever produced.
|
|
33
|
-
*/
|
|
34
|
-
export function sqlStr(value) {
|
|
35
|
-
return value
|
|
36
|
-
.replace(/\\/g, "\\\\")
|
|
37
|
-
.replace(/'/g, "''")
|
|
38
|
-
.replace(/\0/g, "")
|
|
39
|
-
// Drop C0 controls except \t (0x09) \n (0x0A) \r (0x0D), plus DEL (0x7f).
|
|
40
|
-
.replace(/[\x01-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "");
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Escape a string for use inside a `LIKE` / `ILIKE` pattern.
|
|
44
|
-
*
|
|
45
|
-
* Escapes the `LIKE` metacharacters (`%` and `_`) so a literal substring
|
|
46
|
-
* search is never reinterpreted as a wildcard match, alongside the same
|
|
47
|
-
* quote-doubling and control stripping {@link sqlStr} performs. Not currently
|
|
48
|
-
* exercised by the source-graph store's equality-only reads, but ported
|
|
49
|
-
* alongside `sqlStr`/`sqlIdent` so a future prefix/substring query never has
|
|
50
|
-
* to reach for a hand-rolled escape.
|
|
51
|
-
*/
|
|
52
|
-
export function sqlLike(value) {
|
|
53
|
-
return value
|
|
54
|
-
.replace(/[\\%_]/g, "\\$&")
|
|
55
|
-
.replace(/'/g, "''")
|
|
56
|
-
.replace(/\0/g, "")
|
|
57
|
-
.replace(/[\x01-\x08\x0b\x0c\x0e-\x1f\x7f]/g, "");
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Validate a table/column identifier against `^[a-zA-Z_][a-zA-Z0-9_]*$`.
|
|
61
|
-
* Returns the name UNCHANGED on success; throws on anything else.
|
|
62
|
-
*
|
|
63
|
-
* Strict by design: it THROWS rather than sanitizing, because a silently
|
|
64
|
-
* rewritten identifier would be a worse, harder-to-debug failure than a
|
|
65
|
-
* rejected one. Callers pass only known schema names (table and column
|
|
66
|
-
* identifiers from `SOURCE_GRAPH_COLUMNS` / `SOURCE_GRAPH_VERSIONS_COLUMNS`),
|
|
67
|
-
* so a rejection is always a programmer error worth surfacing.
|
|
68
|
-
*/
|
|
69
|
-
export function sqlIdent(name) {
|
|
70
|
-
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {
|
|
71
|
-
throw new Error(`Invalid SQL identifier: ${JSON.stringify(name)}`);
|
|
72
|
-
}
|
|
73
|
-
return name;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Build an ordinary single-quoted literal from a value. Thin convenience
|
|
77
|
-
* around `'${sqlStr(v)}'` so call sites read as a builder call rather than raw
|
|
78
|
-
* quote assembly. Use for ids, paths, hashes, enum-like values, and dates.
|
|
79
|
-
* Use {@link eLiteral} instead when the body may carry escape sequences
|
|
80
|
-
* (free-text title/description/concepts).
|
|
81
|
-
*/
|
|
82
|
-
export function sLiteral(value) {
|
|
83
|
-
return `'${sqlStr(value)}'`;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Build an `E'...'` escape-string literal from a raw text body.
|
|
87
|
-
*
|
|
88
|
-
* Free-text bodies that may contain escape sequences (a description or title
|
|
89
|
-
* with a literal backslash) must use the `E'...'` form so the
|
|
90
|
-
* doubled-backslash escaping from {@link sqlStr} round-trips to the intended
|
|
91
|
-
* bytes; a plain `'...'` literal for a body with backslashes would corrupt it.
|
|
92
|
-
*/
|
|
93
|
-
export function eLiteral(body) {
|
|
94
|
-
return `E'${sqlStr(body)}'`;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Validate and render a numeric value for bare (unquoted) SQL interpolation.
|
|
98
|
-
* Throws unless `value` is, at runtime, a finite JavaScript `number` -
|
|
99
|
-
* TypeScript's `number` type is erased at runtime, so a value that merely
|
|
100
|
-
* carries the `number` type at compile time (e.g. `row.seq`, `row.sizeBytes`,
|
|
101
|
-
* `row.confidence`, or one entry of an embedding vector) is not actually
|
|
102
|
-
* guaranteed to be a safe, quote-free numeric literal unless this is checked
|
|
103
|
-
* here. Without this guard, a non-numeric value smuggled past the type
|
|
104
|
-
* system (a string, `NaN`, `Infinity`, or an object) would be interpolated
|
|
105
|
-
* bare via `String(value)` with no escaping at all - the same injection
|
|
106
|
-
* shape `sqlStr`/`sqlIdent` close for text and identifiers, just for the
|
|
107
|
-
* numeric case. Rejects `NaN`/`Infinity`/`-Infinity` too, since those are not
|
|
108
|
-
* valid bare-numeric SQL tokens.
|
|
109
|
-
*/
|
|
110
|
-
export function sqlNum(value) {
|
|
111
|
-
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
112
|
-
throw new Error(`Invalid SQL numeric value: ${JSON.stringify(value)}`);
|
|
113
|
-
}
|
|
114
|
-
return String(value);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Serialize a `number[]` to a `FLOAT4[]` SQL literal (`ARRAY[...]::float4[]`),
|
|
118
|
-
* mirroring honeycomb's `serializeFloat4Array` (`src/daemon/storage/vector.ts`).
|
|
119
|
-
* Every entry is validated via {@link sqlNum} before interpolation - the
|
|
120
|
-
* dimension contract (`isValidEmbedding`, 768) is a separate application-level
|
|
121
|
-
* check the caller is still responsible for, but this function does not rely
|
|
122
|
-
* on the caller to have validated *finiteness*: a non-numeric or non-finite
|
|
123
|
-
* entry throws here rather than being interpolated bare into the statement.
|
|
124
|
-
*/
|
|
125
|
-
export function sqlFloat4Array(vector) {
|
|
126
|
-
const numbersLit = vector.map((v) => sqlNum(v)).join(",");
|
|
127
|
-
return `ARRAY[${numbersLit}]::float4[]`;
|
|
128
|
-
}
|
|
129
|
-
//# sourceMappingURL=sql-guards.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sql-guards.js","sourceRoot":"","sources":["../../src/source-graph/sql-guards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,MAAM,CAAC,KAAa;IA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AC;IACzE,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAC,MAAyB;IACtD,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC1D,OAAO,SAAS,UAAU,aAAa,CAAC;AAC1C,CAAC"}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The SourceGraphStore seam (PRD-005).
|
|
3
|
-
*
|
|
4
|
-
* The interface both the in-memory adapter (PRD-005, this project, tests + local
|
|
5
|
-
* dev) and the future Deep Lake adapter (the real substrate, per ADR-0002 reached
|
|
6
|
-
* through hivenectar's own client) implement. The file-registration ladder
|
|
7
|
-
* (PRD-006) is written entirely against this interface, so it is testable with the
|
|
8
|
-
* in-memory adapter and unchanged when the Deep Lake adapter lands.
|
|
9
|
-
*
|
|
10
|
-
* All reads/writes are tenancy-scoped (org+workspace at the layer, project_id as a
|
|
11
|
-
* column filter, per PRD-005c). "latest version" always means MAX(seq) for a nectar.
|
|
12
|
-
*/
|
|
13
|
-
import type { SourceGraphRow, SourceGraphVersionRow, Tenancy } from "./model.js";
|
|
14
|
-
/** A candidate for re-association: a nectar plus its latest observed version. */
|
|
15
|
-
export interface LatestVersion {
|
|
16
|
-
readonly identity: SourceGraphRow;
|
|
17
|
-
readonly version: SourceGraphVersionRow;
|
|
18
|
-
}
|
|
19
|
-
export interface SourceGraphStore {
|
|
20
|
-
/** Insert a `source_graph` identity row (mint). Throws if the nectar already exists. */
|
|
21
|
-
insertIdentity(row: SourceGraphRow): void;
|
|
22
|
-
/** Fetch an identity row by nectar, or undefined. */
|
|
23
|
-
getIdentity(nectar: string): SourceGraphRow | undefined;
|
|
24
|
-
/** Bump a nectar's `last_update_date` (called when a new version is appended). */
|
|
25
|
-
touchIdentity(nectar: string, lastUpdateDate: string): void;
|
|
26
|
-
/** Append a `source_graph_versions` row. The caller supplies seq via `nextSeq`. */
|
|
27
|
-
appendVersion(row: SourceGraphVersionRow): void;
|
|
28
|
-
/** The next monotonic seq for a nectar (0 if it has no versions yet). */
|
|
29
|
-
nextSeq(nectar: string): number;
|
|
30
|
-
/** The latest (MAX seq) version row for a nectar, or undefined. */
|
|
31
|
-
latestVersion(nectar: string): SourceGraphVersionRow | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* Every nectar's latest version, scoped to the tenancy. The ladder derives the
|
|
34
|
-
* known-paths set, the missing-files set, and the by-latest-hash copy index from this.
|
|
35
|
-
*/
|
|
36
|
-
listLatestVersions(tenancy: Tenancy): LatestVersion[];
|
|
37
|
-
/** The latest version whose current path equals `path` (ladder steps 1-2), scoped. */
|
|
38
|
-
latestVersionByPath(tenancy: Tenancy, path: string): LatestVersion | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* A nectar whose latest version content_hash equals `contentHash` (ladder step 3
|
|
41
|
-
* exact-move, and the copy-event index), scoped. Returns the first match.
|
|
42
|
-
*/
|
|
43
|
-
latestVersionByHash(tenancy: Tenancy, contentHash: string): LatestVersion | undefined;
|
|
44
|
-
/**
|
|
45
|
-
* Delete a nectar (its identity row + every version row), scoped to `tenancy`.
|
|
46
|
-
* This is the SOLE nectar-deletion path (`prune --confirm`, PRD-006d); the
|
|
47
|
-
* re-association ladder never deletes or reuses nectars. A no-op if the nectar
|
|
48
|
-
* does not exist OR its identity is outside `tenancy` (a cross-project delete
|
|
49
|
-
* is refused, never applied, per AC-20).
|
|
50
|
-
*/
|
|
51
|
-
deleteNectar(tenancy: Tenancy, nectar: string): void;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* The async twin of {@link SourceGraphStore} (PRD-005's Deep Lake adapter).
|
|
55
|
-
*
|
|
56
|
-
* `SourceGraphStore` is synchronous by design: the in-memory adapter backs it
|
|
57
|
-
* with plain `Map`s, and the file-registration ladder (`registration/ladder.ts`)
|
|
58
|
-
* calls it synchronously throughout, with no `await` anywhere in the ladder's
|
|
59
|
-
* control flow. A real Deep Lake adapter does its work over HTTP and cannot
|
|
60
|
-
* honor that synchronous contract, so this is a SEPARATE interface with the
|
|
61
|
-
* same method names and semantics, each wrapped in a `Promise` — not a
|
|
62
|
-
* variant of `SourceGraphStore` and not a substitute for it.
|
|
63
|
-
*
|
|
64
|
-
* `DeepLakeSourceGraphStore` (`deeplake-store.ts`) implements this interface,
|
|
65
|
-
* not `SourceGraphStore`. Wiring the ladder to run against an async store is
|
|
66
|
-
* out of scope for PRD-005's adapter work: that would mean either making the
|
|
67
|
-
* ladder's own control flow async (touching `registration/ladder.ts`, which
|
|
68
|
-
* this task does not touch) or adapting between the two seams at the call
|
|
69
|
-
* site. Either is a future PRD's decision once a caller actually needs the
|
|
70
|
-
* durable adapter wired into the live worker loop; today `InMemorySourceGraphStore`
|
|
71
|
-
* remains the ladder's only consumer and is unchanged by this addition.
|
|
72
|
-
*/
|
|
73
|
-
export interface AsyncSourceGraphStore {
|
|
74
|
-
/** Insert a `source_graph` identity row (mint). Rejects if the nectar already exists. */
|
|
75
|
-
insertIdentity(row: SourceGraphRow): Promise<void>;
|
|
76
|
-
/** Fetch an identity row by nectar, or undefined. */
|
|
77
|
-
getIdentity(nectar: string): Promise<SourceGraphRow | undefined>;
|
|
78
|
-
/** Bump a nectar's `last_update_date` (called when a new version is appended). */
|
|
79
|
-
touchIdentity(nectar: string, lastUpdateDate: string): Promise<void>;
|
|
80
|
-
/** Append a `source_graph_versions` row. The caller supplies seq via `nextSeq`. */
|
|
81
|
-
appendVersion(row: SourceGraphVersionRow): Promise<void>;
|
|
82
|
-
/** The next monotonic seq for a nectar (0 if it has no versions yet). */
|
|
83
|
-
nextSeq(nectar: string): Promise<number>;
|
|
84
|
-
/** The latest (MAX seq) version row for a nectar, or undefined. */
|
|
85
|
-
latestVersion(nectar: string): Promise<SourceGraphVersionRow | undefined>;
|
|
86
|
-
/** Every nectar's latest version, scoped to the tenancy (soft-filtered by `project_id`). */
|
|
87
|
-
listLatestVersions(tenancy: Tenancy): Promise<LatestVersion[]>;
|
|
88
|
-
/** The latest version whose current path equals `path`, scoped. */
|
|
89
|
-
latestVersionByPath(tenancy: Tenancy, path: string): Promise<LatestVersion | undefined>;
|
|
90
|
-
/** A nectar whose latest version content_hash equals `contentHash`, scoped. First match. */
|
|
91
|
-
latestVersionByHash(tenancy: Tenancy, contentHash: string): Promise<LatestVersion | undefined>;
|
|
92
|
-
/**
|
|
93
|
-
* Delete a nectar (identity + versions), scoped to `tenancy`. The SOLE
|
|
94
|
-
* deletion path (`prune --confirm`); a no-op when the nectar does not exist or
|
|
95
|
-
* its identity is outside `tenancy` (a cross-project delete is refused, AC-20).
|
|
96
|
-
* The tenancy predicate makes the Deep Lake adapter inherit the same guard the
|
|
97
|
-
* in-memory adapter enforces, so no delete crosses a project boundary.
|
|
98
|
-
*/
|
|
99
|
-
deleteNectar(tenancy: Tenancy, nectar: string): Promise<void>;
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/source-graph/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EACV,cAAc,EACd,qBAAqB,EACrB,OAAO,EACR,MAAM,YAAY,CAAC;AAEpB,iFAAiF;AACjF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;CACzC;AAED,MAAM,WAAW,gBAAgB;IAC/B,wFAAwF;IACxF,cAAc,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,CAAC;IAE1C,qDAAqD;IACrD,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAAC;IAExD,kFAAkF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C;IAEzC,mEAAmE;IACnE,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAAC;IAE1E,4FAA4F;IAC5F,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAE/D,mEAAmE;IACnE,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IAExF,4FAA4F;IAC5F,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IAE/F;;;;;;OAMG;IACH,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/source-graph/store.ts"],"names":[],"mappings":""}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/** Mint a fresh nectar (26-char ULID). Never derived from content; created once. */
|
|
2
|
-
export declare function mintNectar(nowMs?: number): string;
|
|
3
|
-
/** Decode a nectar's embedded 48-bit timestamp back to milliseconds since epoch. */
|
|
4
|
-
export declare function nectarTimestampMs(nectar: string): number;
|
|
5
|
-
/** The nectar's creation time as an ISO 8601 string (for source_graph.created_at). */
|
|
6
|
-
export declare function nectarCreatedAt(nectar: string): string;
|
|
7
|
-
/** Shape check: 26 chars, all in the Crockford alphabet. */
|
|
8
|
-
export declare function isValidNectar(value: string): boolean;
|
|
9
|
-
//# sourceMappingURL=ulid.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ulid.d.ts","sourceRoot":"","sources":["../../src/source-graph/ulid.ts"],"names":[],"mappings":"AAkCA,oFAAoF;AACpF,wBAAgB,UAAU,CAAC,KAAK,GAAE,MAAmB,GAAG,MAAM,CAE7D;AAED,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CASxD;AAED,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAIpD"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ULID minting for nectars (PRD-005 / PRD-006, per ai/identity-and-reassociation.md).
|
|
3
|
-
*
|
|
4
|
-
* A nectar is a 26-char ULID: 48-bit millisecond timestamp + 80 bits of
|
|
5
|
-
* randomness, Crockford base32, uppercase. Two load-bearing properties (per the
|
|
6
|
-
* corpus): lexicographic sortability by creation time, and registry-free
|
|
7
|
-
* collision resistance so minting is lock-free and parallel-safe. Node built-ins
|
|
8
|
-
* only (`node:crypto`); no `ulid` package dependency.
|
|
9
|
-
*/
|
|
10
|
-
import { randomBytes } from "node:crypto";
|
|
11
|
-
/** Crockford base32 alphabet (excludes I, L, O, U). 32 symbols, 5 bits each. */
|
|
12
|
-
const ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
13
|
-
const TIME_LEN = 10; // 10 chars * 5 bits = 50 bits, covers the 48-bit ms timestamp
|
|
14
|
-
const RANDOM_LEN = 16; // 16 chars * 5 bits = 80 bits of randomness
|
|
15
|
-
function encodeTime(ms, len) {
|
|
16
|
-
let now = Math.floor(ms);
|
|
17
|
-
let out = "";
|
|
18
|
-
for (let i = 0; i < len; i++) {
|
|
19
|
-
out = ENCODING[now % 32] + out;
|
|
20
|
-
now = Math.floor(now / 32);
|
|
21
|
-
}
|
|
22
|
-
return out;
|
|
23
|
-
}
|
|
24
|
-
function encodeRandom(len) {
|
|
25
|
-
// 256 is divisible by 32, so byte % 32 is unbiased across 0..31.
|
|
26
|
-
const bytes = randomBytes(len);
|
|
27
|
-
let out = "";
|
|
28
|
-
for (let i = 0; i < len; i++)
|
|
29
|
-
out += ENCODING[bytes[i] % 32];
|
|
30
|
-
return out;
|
|
31
|
-
}
|
|
32
|
-
/** Mint a fresh nectar (26-char ULID). Never derived from content; created once. */
|
|
33
|
-
export function mintNectar(nowMs = Date.now()) {
|
|
34
|
-
return encodeTime(nowMs, TIME_LEN) + encodeRandom(RANDOM_LEN);
|
|
35
|
-
}
|
|
36
|
-
/** Decode a nectar's embedded 48-bit timestamp back to milliseconds since epoch. */
|
|
37
|
-
export function nectarTimestampMs(nectar) {
|
|
38
|
-
const timeChars = nectar.slice(0, TIME_LEN);
|
|
39
|
-
let ms = 0;
|
|
40
|
-
for (const ch of timeChars) {
|
|
41
|
-
const idx = ENCODING.indexOf(ch);
|
|
42
|
-
if (idx === -1)
|
|
43
|
-
throw new Error(`invalid ULID time char: ${ch}`);
|
|
44
|
-
ms = ms * 32 + idx;
|
|
45
|
-
}
|
|
46
|
-
return ms;
|
|
47
|
-
}
|
|
48
|
-
/** The nectar's creation time as an ISO 8601 string (for source_graph.created_at). */
|
|
49
|
-
export function nectarCreatedAt(nectar) {
|
|
50
|
-
return new Date(nectarTimestampMs(nectar)).toISOString();
|
|
51
|
-
}
|
|
52
|
-
/** Shape check: 26 chars, all in the Crockford alphabet. */
|
|
53
|
-
export function isValidNectar(value) {
|
|
54
|
-
if (value.length !== TIME_LEN + RANDOM_LEN)
|
|
55
|
-
return false;
|
|
56
|
-
for (const ch of value)
|
|
57
|
-
if (ENCODING.indexOf(ch) === -1)
|
|
58
|
-
return false;
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=ulid.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ulid.js","sourceRoot":"","sources":["../../src/source-graph/ulid.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,a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