supastash 0.1.11 → 0.1.12
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/dist/core/schemaManager/index.d.ts.map +1 -1
- package/dist/core/schemaManager/index.js +2 -0
- package/dist/utils/fetchData/createTable.d.ts.map +1 -1
- package/dist/utils/fetchData/createTable.js +12 -2
- package/dist/utils/fetchData/validatePayload.d.ts +2 -0
- package/dist/utils/fetchData/validatePayload.d.ts.map +1 -1
- package/dist/utils/fetchData/validatePayload.js +14 -0
- package/dist/utils/logs.d.ts +4 -0
- package/dist/utils/logs.d.ts.map +1 -1
- package/dist/utils/logs.js +7 -9
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/schemaManager/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAIxE;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,qBAAqB,EAC7B,oBAAoB,UAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/schemaManager/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAIxE;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,qBAAqB,EAC7B,oBAAoB,UAAQ,iBA8C7B"}
|
|
@@ -39,9 +39,11 @@ export async function defineLocalSchema(tableName, schema, deletePreviousSchema
|
|
|
39
39
|
const dropSql = `DROP TABLE IF EXISTS ${tableName}`;
|
|
40
40
|
const clearSyncStatusSql = `DELETE FROM supastash_sync_status WHERE table_name = '${tableName}'`;
|
|
41
41
|
const clearDeleteStatusSql = `DELETE FROM supastash_deleted_status WHERE table_name = '${tableName}'`;
|
|
42
|
+
const clearLastCreatedStatusSql = `DELETE FROM supastash_last_created WHERE table_name = '${tableName}'`;
|
|
42
43
|
await db.execAsync(dropSql);
|
|
43
44
|
await db.execAsync(clearSyncStatusSql);
|
|
44
45
|
await db.execAsync(clearDeleteStatusSql);
|
|
46
|
+
await db.execAsync(clearLastCreatedStatusSql);
|
|
45
47
|
clearSchemaCache(tableName);
|
|
46
48
|
log(`[Supastash] Dropped table ${tableName}`);
|
|
47
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTable.d.ts","sourceRoot":"","sources":["../../../src/utils/fetchData/createTable.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"createTable.d.ts","sourceRoot":"","sources":["../../../src/utils/fetchData/createTable.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AA8CtD;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,iBAsCrE"}
|
|
@@ -5,7 +5,7 @@ import log from "../logs";
|
|
|
5
5
|
import { supabaseClientErr } from "../supabaseClientErr";
|
|
6
6
|
import { checkIfTableExist } from "../tableValidator";
|
|
7
7
|
import { mapPgTypeToSQLite } from "./getKeyType";
|
|
8
|
-
import { validatePayload } from "./validatePayload";
|
|
8
|
+
import { validatePayload, validatePayloadForTable } from "./validatePayload";
|
|
9
9
|
let errorCount = new Map();
|
|
10
10
|
async function getTableSchema(table) {
|
|
11
11
|
const config = getSupastashConfig();
|
|
@@ -27,8 +27,18 @@ async function getTableSchema(table) {
|
|
|
27
27
|
errorCount.set(table, (errorCount.get(table) || 0) + 1);
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
|
+
if (!data || !Array.isArray(data))
|
|
31
|
+
return null;
|
|
32
|
+
validatePayloadForTable(data);
|
|
30
33
|
tableSchemaData.set(table, data);
|
|
31
|
-
return
|
|
34
|
+
return [
|
|
35
|
+
...data,
|
|
36
|
+
{
|
|
37
|
+
column_name: "synced_at",
|
|
38
|
+
data_type: "text",
|
|
39
|
+
is_nullable: "YES",
|
|
40
|
+
},
|
|
41
|
+
];
|
|
32
42
|
}
|
|
33
43
|
/**
|
|
34
44
|
* Creates a table in the database
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { PayloadData } from "../../types/query.types";
|
|
2
|
+
import { TableSchema } from "../../types/realtimeData.types";
|
|
2
3
|
/**
|
|
3
4
|
* Validates the payload
|
|
4
5
|
* @param payload - The payload to validate
|
|
5
6
|
*/
|
|
6
7
|
export declare function validatePayload(payload: PayloadData): Promise<void>;
|
|
8
|
+
export declare function validatePayloadForTable(payload: TableSchema[]): void;
|
|
7
9
|
//# sourceMappingURL=validatePayload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validatePayload.d.ts","sourceRoot":"","sources":["../../../src/utils/fetchData/validatePayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"validatePayload.d.ts","sourceRoot":"","sources":["../../../src/utils/fetchData/validatePayload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE7D;;;GAGG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,WAAW,iBAgBzD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,WAAW,EAAE,QAgB7D"}
|
|
@@ -16,3 +16,17 @@ export async function validatePayload(payload) {
|
|
|
16
16
|
throw new Error("'deleted_at' column of type timestampz is required");
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
export function validatePayloadForTable(payload) {
|
|
20
|
+
if (!payload.some((col) => col.column_name === "id")) {
|
|
21
|
+
throw new Error("Unique 'id' column of type uuid/text is required");
|
|
22
|
+
}
|
|
23
|
+
if (!payload.some((col) => col.column_name === "updated_at")) {
|
|
24
|
+
throw new Error("'updated_at' column of type timestampz is required");
|
|
25
|
+
}
|
|
26
|
+
if (!payload.some((col) => col.column_name === "created_at")) {
|
|
27
|
+
throw new Error("'created_at' column of type timestampz is required");
|
|
28
|
+
}
|
|
29
|
+
if (!payload.some((col) => col.column_name === "deleted_at")) {
|
|
30
|
+
throw new Error("'deleted_at' column of type timestampz is required");
|
|
31
|
+
}
|
|
32
|
+
}
|
package/dist/utils/logs.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ export default log;
|
|
|
9
9
|
* @param args - The arguments to log
|
|
10
10
|
*/
|
|
11
11
|
declare const logError: (...args: any[]) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Logs a warning to the console if debug mode is enabled
|
|
14
|
+
* @param args - The arguments to log
|
|
15
|
+
*/
|
|
12
16
|
declare const logWarn: (...args: any[]) => void;
|
|
13
17
|
export { log, logError, logWarn };
|
|
14
18
|
//# sourceMappingURL=logs.d.ts.map
|
package/dist/utils/logs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/utils/logs.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,QAAA,MAAM,GAAG,GAAI,GAAG,MAAM,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"logs.d.ts","sourceRoot":"","sources":["../../src/utils/logs.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,QAAA,MAAM,GAAG,GAAI,GAAG,MAAM,GAAG,EAAE,SAI1B,CAAC;AAEF,eAAe,GAAG,CAAC;AAEnB;;;GAGG;AACH,QAAA,MAAM,QAAQ,GAAI,GAAG,MAAM,GAAG,EAAE,SAG/B,CAAC;AAEF;;;GAGG;AACH,QAAA,MAAM,OAAO,GAAI,GAAG,MAAM,GAAG,EAAE,SAG9B,CAAC;AAEF,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/utils/logs.js
CHANGED
|
@@ -8,9 +8,7 @@ const log = (...args) => {
|
|
|
8
8
|
const config = getSupastashConfig();
|
|
9
9
|
if (!DEBUG_MODE || !config.debugMode)
|
|
10
10
|
return;
|
|
11
|
-
|
|
12
|
-
Function.prototype.apply.call(console.log, console, args);
|
|
13
|
-
}
|
|
11
|
+
console.log(...args);
|
|
14
12
|
};
|
|
15
13
|
export default log;
|
|
16
14
|
/**
|
|
@@ -20,15 +18,15 @@ export default log;
|
|
|
20
18
|
const logError = (...args) => {
|
|
21
19
|
if (!DEBUG_MODE)
|
|
22
20
|
return;
|
|
23
|
-
|
|
24
|
-
Function.prototype.apply.call(console.error, console, args);
|
|
25
|
-
}
|
|
21
|
+
console.error(...args);
|
|
26
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Logs a warning to the console if debug mode is enabled
|
|
25
|
+
* @param args - The arguments to log
|
|
26
|
+
*/
|
|
27
27
|
const logWarn = (...args) => {
|
|
28
28
|
if (!DEBUG_MODE)
|
|
29
29
|
return;
|
|
30
|
-
|
|
31
|
-
Function.prototype.apply.call(console.warn, console, args);
|
|
32
|
-
}
|
|
30
|
+
console.warn(...args);
|
|
33
31
|
};
|
|
34
32
|
export { log, logError, logWarn };
|