@walkeros/server-destination-sqlite 3.4.0-next-1776749829492
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 +132 -0
- package/dist/dev.d.mts +158 -0
- package/dist/dev.d.ts +158 -0
- package/dist/dev.js +1 -0
- package/dist/dev.js.map +1 -0
- package/dist/dev.mjs +1 -0
- package/dist/dev.mjs.map +1 -0
- package/dist/examples/index.d.mts +110 -0
- package/dist/examples/index.d.ts +110 -0
- package/dist/examples/index.js +214 -0
- package/dist/examples/index.mjs +192 -0
- package/dist/index.d.mts +172 -0
- package/dist/index.d.ts +172 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -0
- package/dist/walkerOS.json +535 -0
- package/package.json +92 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { DestinationServer } from '@walkeros/server-core';
|
|
2
|
+
import { Flow } from '@walkeros/core';
|
|
3
|
+
|
|
4
|
+
type SchemaMode = 'auto' | 'manual';
|
|
5
|
+
/**
|
|
6
|
+
* Thin cross-driver connection interface. Both drivers are adapted to this shape.
|
|
7
|
+
* Production code uses the adapters in src/drivers/*; tests inject a mock client
|
|
8
|
+
* via env.client to capture sql/args without touching a real database.
|
|
9
|
+
*/
|
|
10
|
+
interface SqliteClient {
|
|
11
|
+
/** Execute a SQL statement. Used for CREATE TABLE and ad-hoc commands. */
|
|
12
|
+
execute: (sql: string, args?: ReadonlyArray<unknown>) => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Prepare a statement for repeated execution. Returned function binds args and runs.
|
|
15
|
+
*/
|
|
16
|
+
prepare: (sql: string) => (args: ReadonlyArray<unknown>) => Promise<void>;
|
|
17
|
+
/** Close the connection. */
|
|
18
|
+
close: () => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Factory that constructs an SqliteClient from the user's connection settings.
|
|
22
|
+
* Used by env.SqliteDriver so tests can inject a spy without mocking node_modules.
|
|
23
|
+
*/
|
|
24
|
+
type SqliteClientFactory = (url: string, authToken?: string) => Promise<SqliteClient>;
|
|
25
|
+
interface SqliteSettings {
|
|
26
|
+
/**
|
|
27
|
+
* Connection URL. Starts with `libsql://`, `http://`, `https://`, `wss://`, `ws://`
|
|
28
|
+
* → libSQL driver. Anything else → better-sqlite3 (treated as a file path).
|
|
29
|
+
* Special value `:memory:` → in-memory (better-sqlite3).
|
|
30
|
+
*/
|
|
31
|
+
url: string;
|
|
32
|
+
/** libSQL / Turso auth token. Ignored for better-sqlite3. */
|
|
33
|
+
authToken?: string;
|
|
34
|
+
/** Target table name. Defaults to `events`. */
|
|
35
|
+
table?: string;
|
|
36
|
+
/**
|
|
37
|
+
* `auto` runs `CREATE TABLE IF NOT EXISTS` with the canonical schema on init.
|
|
38
|
+
* `manual` skips CREATE TABLE. The user brings their own schema and mapping.
|
|
39
|
+
* Defaults to `auto`.
|
|
40
|
+
*/
|
|
41
|
+
schema?: SchemaMode;
|
|
42
|
+
_client?: SqliteClient;
|
|
43
|
+
_runInsert?: (args: ReadonlyArray<unknown>) => Promise<void>;
|
|
44
|
+
_ownedClient?: boolean;
|
|
45
|
+
}
|
|
46
|
+
interface Settings {
|
|
47
|
+
sqlite: SqliteSettings;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Env -- optional driver override. Production leaves this undefined and the
|
|
51
|
+
* destination loads better-sqlite3 or @libsql/client dynamically. Tests
|
|
52
|
+
* provide a factory via `SqliteDriver` or a pre-built client via `client`.
|
|
53
|
+
*/
|
|
54
|
+
interface Env extends DestinationServer.Env {
|
|
55
|
+
SqliteDriver?: SqliteClientFactory;
|
|
56
|
+
client?: SqliteClient;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare const push: Env;
|
|
60
|
+
/**
|
|
61
|
+
* Simulation tracking paths. Specifies which function calls to record when
|
|
62
|
+
* running step examples through the collector.
|
|
63
|
+
*/
|
|
64
|
+
declare const simulation: string[];
|
|
65
|
+
|
|
66
|
+
declare const env_push: typeof push;
|
|
67
|
+
declare const env_simulation: typeof simulation;
|
|
68
|
+
declare namespace env {
|
|
69
|
+
export { env_push as push, env_simulation as simulation };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Extended step example that may carry destination-level settings overrides.
|
|
74
|
+
*/
|
|
75
|
+
type SqliteStepExample = Flow.StepExample & {
|
|
76
|
+
settings?: Partial<Settings>;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Canonical insert into the default `events` table. `out` records the
|
|
80
|
+
* column args the prepared INSERT is bound with.
|
|
81
|
+
*/
|
|
82
|
+
declare const defaultInsert: SqliteStepExample;
|
|
83
|
+
/**
|
|
84
|
+
* Custom table name. Verifies table overrides while using the canonical column set.
|
|
85
|
+
*/
|
|
86
|
+
declare const customTable: SqliteStepExample;
|
|
87
|
+
/**
|
|
88
|
+
* Order event with numeric data. Confirms JSON serialization of nested values.
|
|
89
|
+
*/
|
|
90
|
+
declare const orderComplete: SqliteStepExample;
|
|
91
|
+
/**
|
|
92
|
+
* Table override per rule -- routes this event to a dedicated table.
|
|
93
|
+
*/
|
|
94
|
+
declare const tableOverride: SqliteStepExample;
|
|
95
|
+
/**
|
|
96
|
+
* Ignored event -- mapping.ignore: true produces no insert call.
|
|
97
|
+
*/
|
|
98
|
+
declare const ignoredEvent: SqliteStepExample;
|
|
99
|
+
|
|
100
|
+
type step_SqliteStepExample = SqliteStepExample;
|
|
101
|
+
declare const step_customTable: typeof customTable;
|
|
102
|
+
declare const step_defaultInsert: typeof defaultInsert;
|
|
103
|
+
declare const step_ignoredEvent: typeof ignoredEvent;
|
|
104
|
+
declare const step_orderComplete: typeof orderComplete;
|
|
105
|
+
declare const step_tableOverride: typeof tableOverride;
|
|
106
|
+
declare namespace step {
|
|
107
|
+
export { type step_SqliteStepExample as SqliteStepExample, step_customTable as customTable, step_defaultInsert as defaultInsert, step_ignoredEvent as ignoredEvent, step_orderComplete as orderComplete, step_tableOverride as tableOverride };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { env, step };
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/examples/index.ts
|
|
21
|
+
var examples_exports = {};
|
|
22
|
+
__export(examples_exports, {
|
|
23
|
+
env: () => env_exports,
|
|
24
|
+
step: () => step_exports
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(examples_exports);
|
|
27
|
+
|
|
28
|
+
// src/examples/env.ts
|
|
29
|
+
var env_exports = {};
|
|
30
|
+
__export(env_exports, {
|
|
31
|
+
push: () => push,
|
|
32
|
+
simulation: () => simulation
|
|
33
|
+
});
|
|
34
|
+
var asyncExecute = () => Promise.resolve();
|
|
35
|
+
var asyncClose = () => Promise.resolve();
|
|
36
|
+
var asyncPrepare = () => () => Promise.resolve();
|
|
37
|
+
var mockClient = {
|
|
38
|
+
execute: asyncExecute,
|
|
39
|
+
prepare: asyncPrepare,
|
|
40
|
+
close: asyncClose
|
|
41
|
+
};
|
|
42
|
+
var mockFactory = () => Promise.resolve(mockClient);
|
|
43
|
+
var push = {
|
|
44
|
+
SqliteDriver: mockFactory
|
|
45
|
+
};
|
|
46
|
+
var simulation = ["call:client.prepare", "call:client.execute"];
|
|
47
|
+
|
|
48
|
+
// src/examples/step.ts
|
|
49
|
+
var step_exports = {};
|
|
50
|
+
__export(step_exports, {
|
|
51
|
+
customTable: () => customTable,
|
|
52
|
+
defaultInsert: () => defaultInsert,
|
|
53
|
+
ignoredEvent: () => ignoredEvent,
|
|
54
|
+
orderComplete: () => orderComplete,
|
|
55
|
+
tableOverride: () => tableOverride
|
|
56
|
+
});
|
|
57
|
+
var import_core = require("@walkeros/core");
|
|
58
|
+
var defaultInsert = {
|
|
59
|
+
in: (0, import_core.getEvent)("page view", {
|
|
60
|
+
timestamp: 1700000100,
|
|
61
|
+
id: "evt-1",
|
|
62
|
+
user: { session: "sess-1", id: "user-42" },
|
|
63
|
+
data: { title: "Home" },
|
|
64
|
+
source: {
|
|
65
|
+
type: "server",
|
|
66
|
+
id: "https://example.com/",
|
|
67
|
+
previous_id: "https://example.com/prev"
|
|
68
|
+
},
|
|
69
|
+
globals: { env: "prod" },
|
|
70
|
+
consent: { analytics: true }
|
|
71
|
+
}),
|
|
72
|
+
out: [
|
|
73
|
+
[
|
|
74
|
+
"client.runInsert",
|
|
75
|
+
[
|
|
76
|
+
1700000100,
|
|
77
|
+
"evt-1",
|
|
78
|
+
"page view",
|
|
79
|
+
"page",
|
|
80
|
+
"view",
|
|
81
|
+
"sess-1",
|
|
82
|
+
"user-42",
|
|
83
|
+
"https://example.com/",
|
|
84
|
+
"Home",
|
|
85
|
+
"https://example.com/prev",
|
|
86
|
+
JSON.stringify({ title: "Home" }),
|
|
87
|
+
JSON.stringify({ env: "prod" }),
|
|
88
|
+
JSON.stringify({ analytics: true })
|
|
89
|
+
]
|
|
90
|
+
]
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
var customTable = {
|
|
94
|
+
in: (0, import_core.getEvent)("form submit", {
|
|
95
|
+
timestamp: 1700000101,
|
|
96
|
+
id: "evt-2",
|
|
97
|
+
user: { session: "sess-99", id: "" },
|
|
98
|
+
data: { type: "contact" },
|
|
99
|
+
source: {
|
|
100
|
+
type: "server",
|
|
101
|
+
id: "https://example.com/contact",
|
|
102
|
+
previous_id: ""
|
|
103
|
+
},
|
|
104
|
+
globals: {},
|
|
105
|
+
consent: {}
|
|
106
|
+
}),
|
|
107
|
+
settings: {
|
|
108
|
+
sqlite: {
|
|
109
|
+
url: ":memory:",
|
|
110
|
+
table: "siteEvents"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
out: [
|
|
114
|
+
[
|
|
115
|
+
"client.runInsert",
|
|
116
|
+
[
|
|
117
|
+
1700000101,
|
|
118
|
+
"evt-2",
|
|
119
|
+
"form submit",
|
|
120
|
+
"form",
|
|
121
|
+
"submit",
|
|
122
|
+
"sess-99",
|
|
123
|
+
"",
|
|
124
|
+
"https://example.com/contact",
|
|
125
|
+
"",
|
|
126
|
+
"",
|
|
127
|
+
JSON.stringify({ type: "contact" }),
|
|
128
|
+
JSON.stringify({}),
|
|
129
|
+
JSON.stringify({})
|
|
130
|
+
]
|
|
131
|
+
]
|
|
132
|
+
]
|
|
133
|
+
};
|
|
134
|
+
var orderComplete = {
|
|
135
|
+
in: (0, import_core.getEvent)("order complete", {
|
|
136
|
+
timestamp: 1700000102,
|
|
137
|
+
id: "evt-3",
|
|
138
|
+
user: { session: "", id: "" },
|
|
139
|
+
data: { id: "ORD-1", total: 99 },
|
|
140
|
+
source: { type: "server", id: "", previous_id: "" },
|
|
141
|
+
globals: {},
|
|
142
|
+
consent: {}
|
|
143
|
+
}),
|
|
144
|
+
out: [
|
|
145
|
+
[
|
|
146
|
+
"client.runInsert",
|
|
147
|
+
[
|
|
148
|
+
1700000102,
|
|
149
|
+
"evt-3",
|
|
150
|
+
"order complete",
|
|
151
|
+
"order",
|
|
152
|
+
"complete",
|
|
153
|
+
"",
|
|
154
|
+
"",
|
|
155
|
+
"",
|
|
156
|
+
"",
|
|
157
|
+
"",
|
|
158
|
+
JSON.stringify({ id: "ORD-1", total: 99 }),
|
|
159
|
+
JSON.stringify({}),
|
|
160
|
+
JSON.stringify({})
|
|
161
|
+
]
|
|
162
|
+
]
|
|
163
|
+
]
|
|
164
|
+
};
|
|
165
|
+
var tableOverride = {
|
|
166
|
+
in: (0, import_core.getEvent)("order complete", {
|
|
167
|
+
timestamp: 1700000103,
|
|
168
|
+
id: "evt-4",
|
|
169
|
+
user: { session: "", id: "" },
|
|
170
|
+
data: { id: "ORD-2", total: 42 },
|
|
171
|
+
source: { type: "server", id: "", previous_id: "" },
|
|
172
|
+
globals: {},
|
|
173
|
+
consent: {}
|
|
174
|
+
}),
|
|
175
|
+
mapping: {
|
|
176
|
+
settings: {
|
|
177
|
+
table: "orders"
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
out: [
|
|
181
|
+
[
|
|
182
|
+
"client.runInsert",
|
|
183
|
+
[
|
|
184
|
+
1700000103,
|
|
185
|
+
"evt-4",
|
|
186
|
+
"order complete",
|
|
187
|
+
"order",
|
|
188
|
+
"complete",
|
|
189
|
+
"",
|
|
190
|
+
"",
|
|
191
|
+
"",
|
|
192
|
+
"",
|
|
193
|
+
"",
|
|
194
|
+
JSON.stringify({ id: "ORD-2", total: 42 }),
|
|
195
|
+
JSON.stringify({}),
|
|
196
|
+
JSON.stringify({})
|
|
197
|
+
]
|
|
198
|
+
]
|
|
199
|
+
]
|
|
200
|
+
};
|
|
201
|
+
var ignoredEvent = {
|
|
202
|
+
in: (0, import_core.getEvent)("debug noise", {
|
|
203
|
+
timestamp: 1700000104,
|
|
204
|
+
id: "evt-5",
|
|
205
|
+
source: { type: "server", id: "", previous_id: "" }
|
|
206
|
+
}),
|
|
207
|
+
mapping: { ignore: true },
|
|
208
|
+
out: []
|
|
209
|
+
};
|
|
210
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
211
|
+
0 && (module.exports = {
|
|
212
|
+
env,
|
|
213
|
+
step
|
|
214
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/examples/env.ts
|
|
8
|
+
var env_exports = {};
|
|
9
|
+
__export(env_exports, {
|
|
10
|
+
push: () => push,
|
|
11
|
+
simulation: () => simulation
|
|
12
|
+
});
|
|
13
|
+
var asyncExecute = () => Promise.resolve();
|
|
14
|
+
var asyncClose = () => Promise.resolve();
|
|
15
|
+
var asyncPrepare = () => () => Promise.resolve();
|
|
16
|
+
var mockClient = {
|
|
17
|
+
execute: asyncExecute,
|
|
18
|
+
prepare: asyncPrepare,
|
|
19
|
+
close: asyncClose
|
|
20
|
+
};
|
|
21
|
+
var mockFactory = () => Promise.resolve(mockClient);
|
|
22
|
+
var push = {
|
|
23
|
+
SqliteDriver: mockFactory
|
|
24
|
+
};
|
|
25
|
+
var simulation = ["call:client.prepare", "call:client.execute"];
|
|
26
|
+
|
|
27
|
+
// src/examples/step.ts
|
|
28
|
+
var step_exports = {};
|
|
29
|
+
__export(step_exports, {
|
|
30
|
+
customTable: () => customTable,
|
|
31
|
+
defaultInsert: () => defaultInsert,
|
|
32
|
+
ignoredEvent: () => ignoredEvent,
|
|
33
|
+
orderComplete: () => orderComplete,
|
|
34
|
+
tableOverride: () => tableOverride
|
|
35
|
+
});
|
|
36
|
+
import { getEvent } from "@walkeros/core";
|
|
37
|
+
var defaultInsert = {
|
|
38
|
+
in: getEvent("page view", {
|
|
39
|
+
timestamp: 1700000100,
|
|
40
|
+
id: "evt-1",
|
|
41
|
+
user: { session: "sess-1", id: "user-42" },
|
|
42
|
+
data: { title: "Home" },
|
|
43
|
+
source: {
|
|
44
|
+
type: "server",
|
|
45
|
+
id: "https://example.com/",
|
|
46
|
+
previous_id: "https://example.com/prev"
|
|
47
|
+
},
|
|
48
|
+
globals: { env: "prod" },
|
|
49
|
+
consent: { analytics: true }
|
|
50
|
+
}),
|
|
51
|
+
out: [
|
|
52
|
+
[
|
|
53
|
+
"client.runInsert",
|
|
54
|
+
[
|
|
55
|
+
1700000100,
|
|
56
|
+
"evt-1",
|
|
57
|
+
"page view",
|
|
58
|
+
"page",
|
|
59
|
+
"view",
|
|
60
|
+
"sess-1",
|
|
61
|
+
"user-42",
|
|
62
|
+
"https://example.com/",
|
|
63
|
+
"Home",
|
|
64
|
+
"https://example.com/prev",
|
|
65
|
+
JSON.stringify({ title: "Home" }),
|
|
66
|
+
JSON.stringify({ env: "prod" }),
|
|
67
|
+
JSON.stringify({ analytics: true })
|
|
68
|
+
]
|
|
69
|
+
]
|
|
70
|
+
]
|
|
71
|
+
};
|
|
72
|
+
var customTable = {
|
|
73
|
+
in: getEvent("form submit", {
|
|
74
|
+
timestamp: 1700000101,
|
|
75
|
+
id: "evt-2",
|
|
76
|
+
user: { session: "sess-99", id: "" },
|
|
77
|
+
data: { type: "contact" },
|
|
78
|
+
source: {
|
|
79
|
+
type: "server",
|
|
80
|
+
id: "https://example.com/contact",
|
|
81
|
+
previous_id: ""
|
|
82
|
+
},
|
|
83
|
+
globals: {},
|
|
84
|
+
consent: {}
|
|
85
|
+
}),
|
|
86
|
+
settings: {
|
|
87
|
+
sqlite: {
|
|
88
|
+
url: ":memory:",
|
|
89
|
+
table: "siteEvents"
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
out: [
|
|
93
|
+
[
|
|
94
|
+
"client.runInsert",
|
|
95
|
+
[
|
|
96
|
+
1700000101,
|
|
97
|
+
"evt-2",
|
|
98
|
+
"form submit",
|
|
99
|
+
"form",
|
|
100
|
+
"submit",
|
|
101
|
+
"sess-99",
|
|
102
|
+
"",
|
|
103
|
+
"https://example.com/contact",
|
|
104
|
+
"",
|
|
105
|
+
"",
|
|
106
|
+
JSON.stringify({ type: "contact" }),
|
|
107
|
+
JSON.stringify({}),
|
|
108
|
+
JSON.stringify({})
|
|
109
|
+
]
|
|
110
|
+
]
|
|
111
|
+
]
|
|
112
|
+
};
|
|
113
|
+
var orderComplete = {
|
|
114
|
+
in: getEvent("order complete", {
|
|
115
|
+
timestamp: 1700000102,
|
|
116
|
+
id: "evt-3",
|
|
117
|
+
user: { session: "", id: "" },
|
|
118
|
+
data: { id: "ORD-1", total: 99 },
|
|
119
|
+
source: { type: "server", id: "", previous_id: "" },
|
|
120
|
+
globals: {},
|
|
121
|
+
consent: {}
|
|
122
|
+
}),
|
|
123
|
+
out: [
|
|
124
|
+
[
|
|
125
|
+
"client.runInsert",
|
|
126
|
+
[
|
|
127
|
+
1700000102,
|
|
128
|
+
"evt-3",
|
|
129
|
+
"order complete",
|
|
130
|
+
"order",
|
|
131
|
+
"complete",
|
|
132
|
+
"",
|
|
133
|
+
"",
|
|
134
|
+
"",
|
|
135
|
+
"",
|
|
136
|
+
"",
|
|
137
|
+
JSON.stringify({ id: "ORD-1", total: 99 }),
|
|
138
|
+
JSON.stringify({}),
|
|
139
|
+
JSON.stringify({})
|
|
140
|
+
]
|
|
141
|
+
]
|
|
142
|
+
]
|
|
143
|
+
};
|
|
144
|
+
var tableOverride = {
|
|
145
|
+
in: getEvent("order complete", {
|
|
146
|
+
timestamp: 1700000103,
|
|
147
|
+
id: "evt-4",
|
|
148
|
+
user: { session: "", id: "" },
|
|
149
|
+
data: { id: "ORD-2", total: 42 },
|
|
150
|
+
source: { type: "server", id: "", previous_id: "" },
|
|
151
|
+
globals: {},
|
|
152
|
+
consent: {}
|
|
153
|
+
}),
|
|
154
|
+
mapping: {
|
|
155
|
+
settings: {
|
|
156
|
+
table: "orders"
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
out: [
|
|
160
|
+
[
|
|
161
|
+
"client.runInsert",
|
|
162
|
+
[
|
|
163
|
+
1700000103,
|
|
164
|
+
"evt-4",
|
|
165
|
+
"order complete",
|
|
166
|
+
"order",
|
|
167
|
+
"complete",
|
|
168
|
+
"",
|
|
169
|
+
"",
|
|
170
|
+
"",
|
|
171
|
+
"",
|
|
172
|
+
"",
|
|
173
|
+
JSON.stringify({ id: "ORD-2", total: 42 }),
|
|
174
|
+
JSON.stringify({}),
|
|
175
|
+
JSON.stringify({})
|
|
176
|
+
]
|
|
177
|
+
]
|
|
178
|
+
]
|
|
179
|
+
};
|
|
180
|
+
var ignoredEvent = {
|
|
181
|
+
in: getEvent("debug noise", {
|
|
182
|
+
timestamp: 1700000104,
|
|
183
|
+
id: "evt-5",
|
|
184
|
+
source: { type: "server", id: "", previous_id: "" }
|
|
185
|
+
}),
|
|
186
|
+
mapping: { ignore: true },
|
|
187
|
+
out: []
|
|
188
|
+
};
|
|
189
|
+
export {
|
|
190
|
+
env_exports as env,
|
|
191
|
+
step_exports as step
|
|
192
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Destination as Destination$1, Mapping as Mapping$1, Flow, WalkerOS } from '@walkeros/core';
|
|
2
|
+
import { DestinationServer } from '@walkeros/server-core';
|
|
3
|
+
|
|
4
|
+
type SchemaMode = 'auto' | 'manual';
|
|
5
|
+
/**
|
|
6
|
+
* Thin cross-driver connection interface. Both drivers are adapted to this shape.
|
|
7
|
+
* Production code uses the adapters in src/drivers/*; tests inject a mock client
|
|
8
|
+
* via env.client to capture sql/args without touching a real database.
|
|
9
|
+
*/
|
|
10
|
+
interface SqliteClient {
|
|
11
|
+
/** Execute a SQL statement. Used for CREATE TABLE and ad-hoc commands. */
|
|
12
|
+
execute: (sql: string, args?: ReadonlyArray<unknown>) => Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Prepare a statement for repeated execution. Returned function binds args and runs.
|
|
15
|
+
*/
|
|
16
|
+
prepare: (sql: string) => (args: ReadonlyArray<unknown>) => Promise<void>;
|
|
17
|
+
/** Close the connection. */
|
|
18
|
+
close: () => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Factory that constructs an SqliteClient from the user's connection settings.
|
|
22
|
+
* Used by env.SqliteDriver so tests can inject a spy without mocking node_modules.
|
|
23
|
+
*/
|
|
24
|
+
type SqliteClientFactory = (url: string, authToken?: string) => Promise<SqliteClient>;
|
|
25
|
+
interface SqliteSettings {
|
|
26
|
+
/**
|
|
27
|
+
* Connection URL. Starts with `libsql://`, `http://`, `https://`, `wss://`, `ws://`
|
|
28
|
+
* → libSQL driver. Anything else → better-sqlite3 (treated as a file path).
|
|
29
|
+
* Special value `:memory:` → in-memory (better-sqlite3).
|
|
30
|
+
*/
|
|
31
|
+
url: string;
|
|
32
|
+
/** libSQL / Turso auth token. Ignored for better-sqlite3. */
|
|
33
|
+
authToken?: string;
|
|
34
|
+
/** Target table name. Defaults to `events`. */
|
|
35
|
+
table?: string;
|
|
36
|
+
/**
|
|
37
|
+
* `auto` runs `CREATE TABLE IF NOT EXISTS` with the canonical schema on init.
|
|
38
|
+
* `manual` skips CREATE TABLE. The user brings their own schema and mapping.
|
|
39
|
+
* Defaults to `auto`.
|
|
40
|
+
*/
|
|
41
|
+
schema?: SchemaMode;
|
|
42
|
+
_client?: SqliteClient;
|
|
43
|
+
_runInsert?: (args: ReadonlyArray<unknown>) => Promise<void>;
|
|
44
|
+
_ownedClient?: boolean;
|
|
45
|
+
}
|
|
46
|
+
interface Settings {
|
|
47
|
+
sqlite: SqliteSettings;
|
|
48
|
+
}
|
|
49
|
+
type InitSettings = Partial<Settings>;
|
|
50
|
+
interface Mapping {
|
|
51
|
+
/** Override target table for this rule. */
|
|
52
|
+
table?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Env -- optional driver override. Production leaves this undefined and the
|
|
56
|
+
* destination loads better-sqlite3 or @libsql/client dynamically. Tests
|
|
57
|
+
* provide a factory via `SqliteDriver` or a pre-built client via `client`.
|
|
58
|
+
*/
|
|
59
|
+
interface Env extends DestinationServer.Env {
|
|
60
|
+
SqliteDriver?: SqliteClientFactory;
|
|
61
|
+
client?: SqliteClient;
|
|
62
|
+
}
|
|
63
|
+
type Types = Destination$1.Types<Settings, Mapping, Env, InitSettings>;
|
|
64
|
+
interface Destination extends DestinationServer.Destination<Types> {
|
|
65
|
+
init: DestinationServer.InitFn<Types>;
|
|
66
|
+
}
|
|
67
|
+
type Config = {
|
|
68
|
+
settings: Settings;
|
|
69
|
+
} & DestinationServer.Config<Types>;
|
|
70
|
+
type InitFn = DestinationServer.InitFn<Types>;
|
|
71
|
+
type PushFn = DestinationServer.PushFn<Types>;
|
|
72
|
+
type PartialConfig = DestinationServer.PartialConfig<Types>;
|
|
73
|
+
type PushEvents = DestinationServer.PushEvents<Mapping>;
|
|
74
|
+
type Rule = Mapping$1.Rule<Mapping>;
|
|
75
|
+
type Rules = Mapping$1.Rules<Rule>;
|
|
76
|
+
|
|
77
|
+
type index$1_Config = Config;
|
|
78
|
+
type index$1_Destination = Destination;
|
|
79
|
+
type index$1_Env = Env;
|
|
80
|
+
type index$1_InitFn = InitFn;
|
|
81
|
+
type index$1_InitSettings = InitSettings;
|
|
82
|
+
type index$1_Mapping = Mapping;
|
|
83
|
+
type index$1_PartialConfig = PartialConfig;
|
|
84
|
+
type index$1_PushEvents = PushEvents;
|
|
85
|
+
type index$1_PushFn = PushFn;
|
|
86
|
+
type index$1_Rule = Rule;
|
|
87
|
+
type index$1_Rules = Rules;
|
|
88
|
+
type index$1_SchemaMode = SchemaMode;
|
|
89
|
+
type index$1_Settings = Settings;
|
|
90
|
+
type index$1_SqliteClient = SqliteClient;
|
|
91
|
+
type index$1_SqliteClientFactory = SqliteClientFactory;
|
|
92
|
+
type index$1_SqliteSettings = SqliteSettings;
|
|
93
|
+
type index$1_Types = Types;
|
|
94
|
+
declare namespace index$1 {
|
|
95
|
+
export type { index$1_Config as Config, index$1_Destination as Destination, index$1_Env as Env, index$1_InitFn as InitFn, index$1_InitSettings as InitSettings, index$1_Mapping as Mapping, index$1_PartialConfig as PartialConfig, index$1_PushEvents as PushEvents, index$1_PushFn as PushFn, index$1_Rule as Rule, index$1_Rules as Rules, index$1_SchemaMode as SchemaMode, index$1_Settings as Settings, index$1_SqliteClient as SqliteClient, index$1_SqliteClientFactory as SqliteClientFactory, index$1_SqliteSettings as SqliteSettings, index$1_Types as Types };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
declare const push: Env;
|
|
99
|
+
/**
|
|
100
|
+
* Simulation tracking paths. Specifies which function calls to record when
|
|
101
|
+
* running step examples through the collector.
|
|
102
|
+
*/
|
|
103
|
+
declare const simulation: string[];
|
|
104
|
+
|
|
105
|
+
declare const env_push: typeof push;
|
|
106
|
+
declare const env_simulation: typeof simulation;
|
|
107
|
+
declare namespace env {
|
|
108
|
+
export { env_push as push, env_simulation as simulation };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Extended step example that may carry destination-level settings overrides.
|
|
113
|
+
*/
|
|
114
|
+
type SqliteStepExample = Flow.StepExample & {
|
|
115
|
+
settings?: Partial<Settings>;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Canonical insert into the default `events` table. `out` records the
|
|
119
|
+
* column args the prepared INSERT is bound with.
|
|
120
|
+
*/
|
|
121
|
+
declare const defaultInsert: SqliteStepExample;
|
|
122
|
+
/**
|
|
123
|
+
* Custom table name. Verifies table overrides while using the canonical column set.
|
|
124
|
+
*/
|
|
125
|
+
declare const customTable: SqliteStepExample;
|
|
126
|
+
/**
|
|
127
|
+
* Order event with numeric data. Confirms JSON serialization of nested values.
|
|
128
|
+
*/
|
|
129
|
+
declare const orderComplete: SqliteStepExample;
|
|
130
|
+
/**
|
|
131
|
+
* Table override per rule -- routes this event to a dedicated table.
|
|
132
|
+
*/
|
|
133
|
+
declare const tableOverride: SqliteStepExample;
|
|
134
|
+
/**
|
|
135
|
+
* Ignored event -- mapping.ignore: true produces no insert call.
|
|
136
|
+
*/
|
|
137
|
+
declare const ignoredEvent: SqliteStepExample;
|
|
138
|
+
|
|
139
|
+
type step_SqliteStepExample = SqliteStepExample;
|
|
140
|
+
declare const step_customTable: typeof customTable;
|
|
141
|
+
declare const step_defaultInsert: typeof defaultInsert;
|
|
142
|
+
declare const step_ignoredEvent: typeof ignoredEvent;
|
|
143
|
+
declare const step_orderComplete: typeof orderComplete;
|
|
144
|
+
declare const step_tableOverride: typeof tableOverride;
|
|
145
|
+
declare namespace step {
|
|
146
|
+
export { type step_SqliteStepExample as SqliteStepExample, step_customTable as customTable, step_defaultInsert as defaultInsert, step_ignoredEvent as ignoredEvent, step_orderComplete as orderComplete, step_tableOverride as tableOverride };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
declare const index_env: typeof env;
|
|
150
|
+
declare const index_step: typeof step;
|
|
151
|
+
declare namespace index {
|
|
152
|
+
export { index_env as env, index_step as step };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Canonical columns for the auto-created events table. Order matters -- used
|
|
157
|
+
* to build both CREATE TABLE and the prepared INSERT.
|
|
158
|
+
*/
|
|
159
|
+
declare const CANONICAL_COLUMNS: readonly ["timestamp", "event_id", "name", "entity", "action", "session_id", "user_id", "page_url", "page_title", "referrer_url", "data", "globals", "consent"];
|
|
160
|
+
declare function buildCreateTableSql(table: string): string;
|
|
161
|
+
declare function buildInsertSql(table: string): string;
|
|
162
|
+
/**
|
|
163
|
+
* Map a walkerOS event onto the canonical column order. JSON blobs are
|
|
164
|
+
* stringified. Missing fields become empty strings / zeros.
|
|
165
|
+
*/
|
|
166
|
+
declare function eventToRow(event: WalkerOS.Event): unknown[];
|
|
167
|
+
|
|
168
|
+
declare function isLibsqlUrl(url: string): boolean;
|
|
169
|
+
|
|
170
|
+
declare const destinationSQLite: Destination;
|
|
171
|
+
|
|
172
|
+
export { CANONICAL_COLUMNS, index$1 as DestinationSQLite, buildCreateTableSql, buildInsertSql, destinationSQLite as default, destinationSQLite, eventToRow, index as examples, isLibsqlUrl };
|