latticesql 0.18.4 → 1.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/README.md +5 -1
- package/dist/cli.js +6 -1
- package/dist/index.cjs +69 -4
- package/dist/index.d.cts +18 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.js +68 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -969,7 +969,11 @@ const task = await db.updateReturning('tasks', 'task-001', { status: 'done' });
|
|
|
969
969
|
// task → { id: 'task-001', title: 'Write docs', status: 'done', priority: 3, ... }
|
|
970
970
|
|
|
971
971
|
// Composite PK
|
|
972
|
-
const seat = await db.updateReturning(
|
|
972
|
+
const seat = await db.updateReturning(
|
|
973
|
+
'event_seats',
|
|
974
|
+
{ event_id: 'e-1', seat_no: 3 },
|
|
975
|
+
{ holder: 'Bob' },
|
|
976
|
+
);
|
|
973
977
|
// seat → { event_id: 'e-1', seat_no: 3, holder: 'Bob' }
|
|
974
978
|
```
|
|
975
979
|
|
package/dist/cli.js
CHANGED
|
@@ -1712,7 +1712,12 @@ var Lattice = class {
|
|
|
1712
1712
|
this._assertNotInit("define");
|
|
1713
1713
|
const compiledDef = {
|
|
1714
1714
|
...def,
|
|
1715
|
-
render: def.render ? compileRender(
|
|
1715
|
+
render: def.render ? compileRender(
|
|
1716
|
+
def,
|
|
1717
|
+
table,
|
|
1718
|
+
this._schema,
|
|
1719
|
+
this._adapter
|
|
1720
|
+
) : () => "",
|
|
1716
1721
|
outputFile: def.outputFile ?? `.schema-only/${table}.md`
|
|
1717
1722
|
};
|
|
1718
1723
|
this._schema.define(table, compiledDef);
|
package/dist/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ __export(index_exports, {
|
|
|
36
36
|
Lattice: () => Lattice,
|
|
37
37
|
READ_ONLY_HEADER: () => READ_ONLY_HEADER,
|
|
38
38
|
applyWriteEntry: () => applyWriteEntry,
|
|
39
|
+
autoUpdate: () => autoUpdate,
|
|
39
40
|
contentHash: () => contentHash,
|
|
40
41
|
createReadOnlyHeader: () => createReadOnlyHeader,
|
|
41
42
|
createSQLiteStateStore: () => createSQLiteStateStore,
|
|
@@ -1755,7 +1756,12 @@ var Lattice = class {
|
|
|
1755
1756
|
this._assertNotInit("define");
|
|
1756
1757
|
const compiledDef = {
|
|
1757
1758
|
...def,
|
|
1758
|
-
render: def.render ? compileRender(
|
|
1759
|
+
render: def.render ? compileRender(
|
|
1760
|
+
def,
|
|
1761
|
+
table,
|
|
1762
|
+
this._schema,
|
|
1763
|
+
this._adapter
|
|
1764
|
+
) : () => "",
|
|
1759
1765
|
outputFile: def.outputFile ?? `.schema-only/${table}.md`
|
|
1760
1766
|
};
|
|
1761
1767
|
this._schema.define(table, compiledDef);
|
|
@@ -2676,9 +2682,7 @@ function fixSchemaConflicts(db, checks) {
|
|
|
2676
2682
|
if (tableExists(db, "__lattice_migrations")) {
|
|
2677
2683
|
const versionCol = db.prepare('PRAGMA table_info("__lattice_migrations")').all().find((c) => c.name === "version");
|
|
2678
2684
|
if (versionCol?.type.toUpperCase().includes("INTEGER")) {
|
|
2679
|
-
db.exec(
|
|
2680
|
-
'ALTER TABLE "__lattice_migrations" RENAME TO "__lattice_migrations_v1"'
|
|
2681
|
-
);
|
|
2685
|
+
db.exec('ALTER TABLE "__lattice_migrations" RENAME TO "__lattice_migrations_v1"');
|
|
2682
2686
|
}
|
|
2683
2687
|
}
|
|
2684
2688
|
}
|
|
@@ -3098,6 +3102,66 @@ function applyWriteEntry(db, entry) {
|
|
|
3098
3102
|
return { ok: false, reason: `DB error: ${message}` };
|
|
3099
3103
|
}
|
|
3100
3104
|
}
|
|
3105
|
+
|
|
3106
|
+
// src/auto-update.ts
|
|
3107
|
+
var import_node_child_process = require("child_process");
|
|
3108
|
+
var import_node_fs8 = require("fs");
|
|
3109
|
+
var import_node_path8 = require("path");
|
|
3110
|
+
function getInstalledVersion(pkgName) {
|
|
3111
|
+
try {
|
|
3112
|
+
const pkgPath = (0, import_node_path8.join)(process.cwd(), "node_modules", pkgName, "package.json");
|
|
3113
|
+
const pkg = JSON.parse((0, import_node_fs8.readFileSync)(pkgPath, "utf-8"));
|
|
3114
|
+
return pkg.version;
|
|
3115
|
+
} catch {
|
|
3116
|
+
return null;
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
async function getLatestVersion(pkgName) {
|
|
3120
|
+
try {
|
|
3121
|
+
const res = await fetch(`https://registry.npmjs.org/${pkgName}/latest`, {
|
|
3122
|
+
headers: { accept: "application/json" },
|
|
3123
|
+
signal: AbortSignal.timeout(5e3)
|
|
3124
|
+
});
|
|
3125
|
+
if (!res.ok) return null;
|
|
3126
|
+
const data = await res.json();
|
|
3127
|
+
return data.version;
|
|
3128
|
+
} catch {
|
|
3129
|
+
return null;
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
function isNewer(latest, current) {
|
|
3133
|
+
const a = latest.split(".").map(Number);
|
|
3134
|
+
const b = current.split(".").map(Number);
|
|
3135
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
3136
|
+
if ((a[i] ?? 0) > (b[i] ?? 0)) return true;
|
|
3137
|
+
if ((a[i] ?? 0) < (b[i] ?? 0)) return false;
|
|
3138
|
+
}
|
|
3139
|
+
return false;
|
|
3140
|
+
}
|
|
3141
|
+
async function autoUpdate(opts) {
|
|
3142
|
+
const log = opts?.quiet ? () => {
|
|
3143
|
+
} : console.log;
|
|
3144
|
+
const result = { updated: false, packages: [], restartRequired: false };
|
|
3145
|
+
const installed = getInstalledVersion("latticesql");
|
|
3146
|
+
if (!installed) return result;
|
|
3147
|
+
const latest = await getLatestVersion("latticesql");
|
|
3148
|
+
if (!latest || !isNewer(latest, installed)) return result;
|
|
3149
|
+
log(`[latticesql] Updating: latticesql@${installed} \u2192 ${latest}`);
|
|
3150
|
+
try {
|
|
3151
|
+
(0, import_node_child_process.execSync)(`npm install latticesql@${latest}`, {
|
|
3152
|
+
cwd: process.cwd(),
|
|
3153
|
+
stdio: opts?.quiet ? "ignore" : "inherit",
|
|
3154
|
+
timeout: 6e4
|
|
3155
|
+
});
|
|
3156
|
+
result.updated = true;
|
|
3157
|
+
result.restartRequired = true;
|
|
3158
|
+
result.packages.push({ name: "latticesql", from: installed, to: latest });
|
|
3159
|
+
log(`[latticesql] Updated successfully. Restart required.`);
|
|
3160
|
+
} catch (err) {
|
|
3161
|
+
console.error("[latticesql] Auto-update failed:", err);
|
|
3162
|
+
}
|
|
3163
|
+
return result;
|
|
3164
|
+
}
|
|
3101
3165
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3102
3166
|
0 && (module.exports = {
|
|
3103
3167
|
DEFAULT_ENTRY_TYPES,
|
|
@@ -3106,6 +3170,7 @@ function applyWriteEntry(db, entry) {
|
|
|
3106
3170
|
Lattice,
|
|
3107
3171
|
READ_ONLY_HEADER,
|
|
3108
3172
|
applyWriteEntry,
|
|
3173
|
+
autoUpdate,
|
|
3109
3174
|
contentHash,
|
|
3110
3175
|
createReadOnlyHeader,
|
|
3111
3176
|
createSQLiteStateStore,
|
package/dist/index.d.cts
CHANGED
|
@@ -1810,4 +1810,21 @@ declare function createReadOnlyHeader(options?: ReadOnlyHeaderOptions): string;
|
|
|
1810
1810
|
*/
|
|
1811
1811
|
declare const READ_ONLY_HEADER: string;
|
|
1812
1812
|
|
|
1813
|
-
|
|
1813
|
+
interface AutoUpdateResult {
|
|
1814
|
+
updated: boolean;
|
|
1815
|
+
packages: Array<{
|
|
1816
|
+
name: string;
|
|
1817
|
+
from: string;
|
|
1818
|
+
to: string;
|
|
1819
|
+
}>;
|
|
1820
|
+
restartRequired: boolean;
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Check npm for a newer version of latticesql and install it.
|
|
1824
|
+
* Safe to call on every startup — skips if already on latest.
|
|
1825
|
+
*/
|
|
1826
|
+
declare function autoUpdate(opts?: {
|
|
1827
|
+
quiet?: boolean;
|
|
1828
|
+
}): Promise<AutoUpdateResult>;
|
|
1829
|
+
|
|
1830
|
+
export { type ApplyWriteResult, type AuditEvent, type AutoUpdateResult, type BelongsToRelation, type BelongsToSource, type BuiltinTemplateName, type CleanupOptions, type CleanupResult, type CountOptions, type CustomSource, DEFAULT_ENTRY_TYPES, DEFAULT_TYPE_ALIASES, type EnrichedSource, type EnrichmentLookup, type EntityContextDefinition, type EntityContextManifestEntry, type EntityFileManifestInfo, type EntityFileSource, type EntityFileSpec, type EntityProfileField, type EntityProfileSection, type EntityProfileTemplate, type EntityRenderSpec, type EntityRenderTemplate, type EntitySectionPerRow, type EntitySectionsTemplate, type EntityTableColumn, type EntityTableTemplate, type Filter, type FilterOp, type HasManyRelation, type HasManySource, InMemoryStateStore, type InitOptions, Lattice, type LatticeConfig, type LatticeConfigInput, type LatticeEntityDef, type LatticeEntityRenderSpec, type LatticeFieldDef, type LatticeFieldType, type LatticeManifest, type LatticeOptions, type LinkOptions, type ManyToManySource, type MarkdownTableColumn, type Migration, type MultiTableDefinition, type OrderBySpec, type ParseError, type ParseResult, type ParsedConfig, type PkLookup, type PrimaryKey, type QueryOptions, READ_ONLY_HEADER, type ReadOnlyHeaderOptions, type ReconcileOptions, type ReconcileResult, type Relation, type RenderHooks, type RenderResult, type RenderSpec, type ReportConfig, type ReportResult, type ReportSection, type ReportSectionResult, type ReverseSyncError, type ReverseSyncResult, type ReverseSyncUpdate, type Row, type SecurityOptions, type SeedConfig, type SeedLinkSpec, type SeedResult, type SelfSource, type SessionEntry, type SessionParseOptions, type SessionWriteEntry, type SessionWriteOp, type SessionWriteParseResult, type SourceQueryOptions, type StopFn, type SyncResult, type TableDefinition, type TemplateRenderSpec, type UpsertByNaturalKeyOptions, type WatchOptions, type WriteHook, type WriteHookContext, type WritebackDefinition, type WritebackStateStore, applyWriteEntry, autoUpdate, contentHash, createReadOnlyHeader, createSQLiteStateStore, decrypt, deriveKey, encrypt, entityFileNames, fixSchemaConflicts, frontmatter, generateEntryId, generateWriteEntryId, isEncrypted, isV1EntityFiles, manifestPath, markdownTable, normalizeEntityFiles, parseConfigFile, parseConfigString, parseMarkdownEntries, parseSessionMD, parseSessionWrites, readManifest, slugify, truncate, validateEntryId, writeManifest };
|
package/dist/index.d.ts
CHANGED
|
@@ -1810,4 +1810,21 @@ declare function createReadOnlyHeader(options?: ReadOnlyHeaderOptions): string;
|
|
|
1810
1810
|
*/
|
|
1811
1811
|
declare const READ_ONLY_HEADER: string;
|
|
1812
1812
|
|
|
1813
|
-
|
|
1813
|
+
interface AutoUpdateResult {
|
|
1814
|
+
updated: boolean;
|
|
1815
|
+
packages: Array<{
|
|
1816
|
+
name: string;
|
|
1817
|
+
from: string;
|
|
1818
|
+
to: string;
|
|
1819
|
+
}>;
|
|
1820
|
+
restartRequired: boolean;
|
|
1821
|
+
}
|
|
1822
|
+
/**
|
|
1823
|
+
* Check npm for a newer version of latticesql and install it.
|
|
1824
|
+
* Safe to call on every startup — skips if already on latest.
|
|
1825
|
+
*/
|
|
1826
|
+
declare function autoUpdate(opts?: {
|
|
1827
|
+
quiet?: boolean;
|
|
1828
|
+
}): Promise<AutoUpdateResult>;
|
|
1829
|
+
|
|
1830
|
+
export { type ApplyWriteResult, type AuditEvent, type AutoUpdateResult, type BelongsToRelation, type BelongsToSource, type BuiltinTemplateName, type CleanupOptions, type CleanupResult, type CountOptions, type CustomSource, DEFAULT_ENTRY_TYPES, DEFAULT_TYPE_ALIASES, type EnrichedSource, type EnrichmentLookup, type EntityContextDefinition, type EntityContextManifestEntry, type EntityFileManifestInfo, type EntityFileSource, type EntityFileSpec, type EntityProfileField, type EntityProfileSection, type EntityProfileTemplate, type EntityRenderSpec, type EntityRenderTemplate, type EntitySectionPerRow, type EntitySectionsTemplate, type EntityTableColumn, type EntityTableTemplate, type Filter, type FilterOp, type HasManyRelation, type HasManySource, InMemoryStateStore, type InitOptions, Lattice, type LatticeConfig, type LatticeConfigInput, type LatticeEntityDef, type LatticeEntityRenderSpec, type LatticeFieldDef, type LatticeFieldType, type LatticeManifest, type LatticeOptions, type LinkOptions, type ManyToManySource, type MarkdownTableColumn, type Migration, type MultiTableDefinition, type OrderBySpec, type ParseError, type ParseResult, type ParsedConfig, type PkLookup, type PrimaryKey, type QueryOptions, READ_ONLY_HEADER, type ReadOnlyHeaderOptions, type ReconcileOptions, type ReconcileResult, type Relation, type RenderHooks, type RenderResult, type RenderSpec, type ReportConfig, type ReportResult, type ReportSection, type ReportSectionResult, type ReverseSyncError, type ReverseSyncResult, type ReverseSyncUpdate, type Row, type SecurityOptions, type SeedConfig, type SeedLinkSpec, type SeedResult, type SelfSource, type SessionEntry, type SessionParseOptions, type SessionWriteEntry, type SessionWriteOp, type SessionWriteParseResult, type SourceQueryOptions, type StopFn, type SyncResult, type TableDefinition, type TemplateRenderSpec, type UpsertByNaturalKeyOptions, type WatchOptions, type WriteHook, type WriteHookContext, type WritebackDefinition, type WritebackStateStore, applyWriteEntry, autoUpdate, contentHash, createReadOnlyHeader, createSQLiteStateStore, decrypt, deriveKey, encrypt, entityFileNames, fixSchemaConflicts, frontmatter, generateEntryId, generateWriteEntryId, isEncrypted, isV1EntityFiles, manifestPath, markdownTable, normalizeEntityFiles, parseConfigFile, parseConfigString, parseMarkdownEntries, parseSessionMD, parseSessionWrites, readManifest, slugify, truncate, validateEntryId, writeManifest };
|
package/dist/index.js
CHANGED
|
@@ -1688,7 +1688,12 @@ var Lattice = class {
|
|
|
1688
1688
|
this._assertNotInit("define");
|
|
1689
1689
|
const compiledDef = {
|
|
1690
1690
|
...def,
|
|
1691
|
-
render: def.render ? compileRender(
|
|
1691
|
+
render: def.render ? compileRender(
|
|
1692
|
+
def,
|
|
1693
|
+
table,
|
|
1694
|
+
this._schema,
|
|
1695
|
+
this._adapter
|
|
1696
|
+
) : () => "",
|
|
1692
1697
|
outputFile: def.outputFile ?? `.schema-only/${table}.md`
|
|
1693
1698
|
};
|
|
1694
1699
|
this._schema.define(table, compiledDef);
|
|
@@ -2609,9 +2614,7 @@ function fixSchemaConflicts(db, checks) {
|
|
|
2609
2614
|
if (tableExists(db, "__lattice_migrations")) {
|
|
2610
2615
|
const versionCol = db.prepare('PRAGMA table_info("__lattice_migrations")').all().find((c) => c.name === "version");
|
|
2611
2616
|
if (versionCol?.type.toUpperCase().includes("INTEGER")) {
|
|
2612
|
-
db.exec(
|
|
2613
|
-
'ALTER TABLE "__lattice_migrations" RENAME TO "__lattice_migrations_v1"'
|
|
2614
|
-
);
|
|
2617
|
+
db.exec('ALTER TABLE "__lattice_migrations" RENAME TO "__lattice_migrations_v1"');
|
|
2615
2618
|
}
|
|
2616
2619
|
}
|
|
2617
2620
|
}
|
|
@@ -3031,6 +3034,66 @@ function applyWriteEntry(db, entry) {
|
|
|
3031
3034
|
return { ok: false, reason: `DB error: ${message}` };
|
|
3032
3035
|
}
|
|
3033
3036
|
}
|
|
3037
|
+
|
|
3038
|
+
// src/auto-update.ts
|
|
3039
|
+
import { execSync } from "child_process";
|
|
3040
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
3041
|
+
import { join as join7 } from "path";
|
|
3042
|
+
function getInstalledVersion(pkgName) {
|
|
3043
|
+
try {
|
|
3044
|
+
const pkgPath = join7(process.cwd(), "node_modules", pkgName, "package.json");
|
|
3045
|
+
const pkg = JSON.parse(readFileSync6(pkgPath, "utf-8"));
|
|
3046
|
+
return pkg.version;
|
|
3047
|
+
} catch {
|
|
3048
|
+
return null;
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
async function getLatestVersion(pkgName) {
|
|
3052
|
+
try {
|
|
3053
|
+
const res = await fetch(`https://registry.npmjs.org/${pkgName}/latest`, {
|
|
3054
|
+
headers: { accept: "application/json" },
|
|
3055
|
+
signal: AbortSignal.timeout(5e3)
|
|
3056
|
+
});
|
|
3057
|
+
if (!res.ok) return null;
|
|
3058
|
+
const data = await res.json();
|
|
3059
|
+
return data.version;
|
|
3060
|
+
} catch {
|
|
3061
|
+
return null;
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
function isNewer(latest, current) {
|
|
3065
|
+
const a = latest.split(".").map(Number);
|
|
3066
|
+
const b = current.split(".").map(Number);
|
|
3067
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
3068
|
+
if ((a[i] ?? 0) > (b[i] ?? 0)) return true;
|
|
3069
|
+
if ((a[i] ?? 0) < (b[i] ?? 0)) return false;
|
|
3070
|
+
}
|
|
3071
|
+
return false;
|
|
3072
|
+
}
|
|
3073
|
+
async function autoUpdate(opts) {
|
|
3074
|
+
const log = opts?.quiet ? () => {
|
|
3075
|
+
} : console.log;
|
|
3076
|
+
const result = { updated: false, packages: [], restartRequired: false };
|
|
3077
|
+
const installed = getInstalledVersion("latticesql");
|
|
3078
|
+
if (!installed) return result;
|
|
3079
|
+
const latest = await getLatestVersion("latticesql");
|
|
3080
|
+
if (!latest || !isNewer(latest, installed)) return result;
|
|
3081
|
+
log(`[latticesql] Updating: latticesql@${installed} \u2192 ${latest}`);
|
|
3082
|
+
try {
|
|
3083
|
+
execSync(`npm install latticesql@${latest}`, {
|
|
3084
|
+
cwd: process.cwd(),
|
|
3085
|
+
stdio: opts?.quiet ? "ignore" : "inherit",
|
|
3086
|
+
timeout: 6e4
|
|
3087
|
+
});
|
|
3088
|
+
result.updated = true;
|
|
3089
|
+
result.restartRequired = true;
|
|
3090
|
+
result.packages.push({ name: "latticesql", from: installed, to: latest });
|
|
3091
|
+
log(`[latticesql] Updated successfully. Restart required.`);
|
|
3092
|
+
} catch (err) {
|
|
3093
|
+
console.error("[latticesql] Auto-update failed:", err);
|
|
3094
|
+
}
|
|
3095
|
+
return result;
|
|
3096
|
+
}
|
|
3034
3097
|
export {
|
|
3035
3098
|
DEFAULT_ENTRY_TYPES,
|
|
3036
3099
|
DEFAULT_TYPE_ALIASES,
|
|
@@ -3038,6 +3101,7 @@ export {
|
|
|
3038
3101
|
Lattice,
|
|
3039
3102
|
READ_ONLY_HEADER,
|
|
3040
3103
|
applyWriteEntry,
|
|
3104
|
+
autoUpdate,
|
|
3041
3105
|
contentHash,
|
|
3042
3106
|
createReadOnlyHeader,
|
|
3043
3107
|
createSQLiteStateStore,
|