local-lite 0.1.0 → 0.1.2
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 +10 -3
- package/bin/local-lite.mjs +62 -0
- package/dist/adapters/network/index.js +3 -1
- package/dist/adapters/remote/firestore.js +4 -2
- package/dist/core/table-manager.js +13 -3
- package/dist/storage/driver.js +9 -2
- package/dist/storage/expo.js +9 -5
- package/dist/utils/dynamic.js +24 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -93,9 +93,16 @@ For an application-level upgrade checklist or AI-assisted code review, see the
|
|
|
93
93
|
## AI Skills
|
|
94
94
|
|
|
95
95
|
The package ships [Agent Skills](./skills) that AI coding assistants can load:
|
|
96
|
-
`local-lite-setup`, `local-lite-custom-adapter` and `local-lite-upgrade`.
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
`local-lite-setup`, `local-lite-custom-adapter` and `local-lite-upgrade`.
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
npx local-lite install-skills # Copilot: .github/skills
|
|
100
|
+
npx local-lite install-skills --target claude # Claude Code: .claude/skills
|
|
101
|
+
npx local-lite install-skills --dir path/to/dir --force
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Without npm, fetch them from GitHub:
|
|
105
|
+
`npx degit georgechitechi/local-lite/skills .github/skills`.
|
|
99
106
|
|
|
100
107
|
## Features
|
|
101
108
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { cp, mkdir, readdir } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const skillsRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'skills');
|
|
7
|
+
const targets = {
|
|
8
|
+
copilot: '.github/skills',
|
|
9
|
+
claude: '.claude/skills',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const usage = `Usage: local-lite install-skills [--target copilot|claude] [--dir <path>] [--force]
|
|
13
|
+
|
|
14
|
+
Copies the bundled AI skills into your project.
|
|
15
|
+
--target copilot (default, .github/skills) or claude (.claude/skills)
|
|
16
|
+
--dir custom destination directory (overrides --target)
|
|
17
|
+
--force overwrite existing skill files`;
|
|
18
|
+
|
|
19
|
+
function parseArgs(argv) {
|
|
20
|
+
const options = { target: 'copilot', dir: undefined, force: false };
|
|
21
|
+
for (let i = 0; i < argv.length; i++) {
|
|
22
|
+
const arg = argv[i];
|
|
23
|
+
if (arg === '--force') options.force = true;
|
|
24
|
+
else if (arg === '--target') options.target = argv[++i];
|
|
25
|
+
else if (arg === '--dir') {
|
|
26
|
+
options.dir = argv[++i];
|
|
27
|
+
if (!options.dir) throw new Error('--dir requires a path.');
|
|
28
|
+
} else throw new Error(`Unknown option: ${arg}`);
|
|
29
|
+
}
|
|
30
|
+
if (!options.dir && !targets[options.target]) {
|
|
31
|
+
throw new Error(`Unknown target "${options.target}". Use copilot or claude.`);
|
|
32
|
+
}
|
|
33
|
+
return options;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function installSkills(options) {
|
|
37
|
+
const destination = path.resolve(process.cwd(), options.dir ?? targets[options.target]);
|
|
38
|
+
await mkdir(destination, { recursive: true });
|
|
39
|
+
const entries = await readdir(skillsRoot, { withFileTypes: true });
|
|
40
|
+
for (const entry of entries.filter((item) => item.isDirectory())) {
|
|
41
|
+
await cp(path.join(skillsRoot, entry.name), path.join(destination, entry.name), {
|
|
42
|
+
recursive: true,
|
|
43
|
+
force: options.force,
|
|
44
|
+
errorOnExist: false,
|
|
45
|
+
});
|
|
46
|
+
console.log(`Installed ${entry.name} -> ${path.join(destination, entry.name)}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
51
|
+
try {
|
|
52
|
+
if (command === 'install-skills') {
|
|
53
|
+
await installSkills(parseArgs(rest));
|
|
54
|
+
} else {
|
|
55
|
+
console.log(usage);
|
|
56
|
+
process.exitCode = command && command !== '--help' && command !== '-h' ? 1 : 0;
|
|
57
|
+
}
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error(error instanceof Error ? error.message : error);
|
|
60
|
+
console.error(usage);
|
|
61
|
+
process.exitCode = 1;
|
|
62
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DefaultNetworkStatusProvider = void 0;
|
|
4
|
+
const dynamic_js_1 = require("../../utils/dynamic.js");
|
|
5
|
+
const NETINFO_PKG = ['@react-native-community', 'netinfo'].join('/');
|
|
4
6
|
class DefaultNetworkStatusProvider {
|
|
5
7
|
_isOnline = true;
|
|
6
8
|
listeners = new Set();
|
|
@@ -9,7 +11,7 @@ class DefaultNetworkStatusProvider {
|
|
|
9
11
|
this._isOnline = initialOnline;
|
|
10
12
|
// 1. Try React Native NetInfo if available in environment
|
|
11
13
|
try {
|
|
12
|
-
const NetInfo =
|
|
14
|
+
const NetInfo = (0, dynamic_js_1.safeDynamicRequire)(NETINFO_PKG);
|
|
13
15
|
const netInfoInstance = NetInfo?.default || NetInfo;
|
|
14
16
|
if (netInfoInstance && typeof netInfoInstance.addEventListener === 'function') {
|
|
15
17
|
netInfoInstance
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createFirebaseStorageUploader = exports.FirestoreAdapter = exports.FirestoreRemoteAdapter = void 0;
|
|
4
|
+
const dynamic_js_1 = require("../../utils/dynamic.js");
|
|
4
5
|
const logger_js_1 = require("../../utils/logger.js");
|
|
5
6
|
const firebase_js_1 = require("../../storage/firebase.js");
|
|
6
7
|
Object.defineProperty(exports, "createFirebaseStorageUploader", { enumerable: true, get: function () { return firebase_js_1.createFirebaseStorageUploader; } });
|
|
@@ -68,8 +69,9 @@ class FirestoreRemoteAdapter {
|
|
|
68
69
|
return this.firestoreModule;
|
|
69
70
|
}
|
|
70
71
|
try {
|
|
71
|
-
const
|
|
72
|
-
this.firestoreModule =
|
|
72
|
+
const FIRESTORE_PKG = ['firebase', 'firestore'].join('/');
|
|
73
|
+
this.firestoreModule =
|
|
74
|
+
(0, dynamic_js_1.safeDynamicRequire)(FIRESTORE_PKG) ?? (await (0, dynamic_js_1.safeDynamicImport)(FIRESTORE_PKG));
|
|
73
75
|
return this.firestoreModule;
|
|
74
76
|
}
|
|
75
77
|
catch {
|
|
@@ -50,10 +50,20 @@ class TableManager {
|
|
|
50
50
|
const keys = Object.keys(rowData);
|
|
51
51
|
if (keys.length === 0)
|
|
52
52
|
return;
|
|
53
|
-
// Use atomic SQLite UPSERT (INSERT ... ON CONFLICT DO UPDATE) for
|
|
54
|
-
//
|
|
55
|
-
// completely eliminating the redundant SELECT 1 pre-check on every mutation!
|
|
53
|
+
// Use atomic SQLite UPSERT (INSERT ... ON CONFLICT DO UPDATE) for INSERT,
|
|
54
|
+
// and direct UPDATE when updating an existing row so omitted NOT NULL columns do not fail.
|
|
56
55
|
const updateKeys = keys.filter((k) => k !== primaryKey);
|
|
56
|
+
if (operation === 'UPDATE' && updateKeys.length > 0) {
|
|
57
|
+
const existing = await TableManager.fetchRow(tx, tableName, rowId, primaryKey, options);
|
|
58
|
+
if (existing) {
|
|
59
|
+
const setClause = updateKeys
|
|
60
|
+
.map((k) => `${(0, sql_js_1.escapeIdentifier)(k)} = ?`)
|
|
61
|
+
.join(', ');
|
|
62
|
+
const setValues = [...updateKeys.map((k) => rowData[k]), rowId];
|
|
63
|
+
await tx.execute(`UPDATE ${safeTable} SET ${setClause} WHERE ${safePk} = ?`, setValues);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
57
67
|
const cols = keys.map((k) => (0, sql_js_1.escapeIdentifier)(k)).join(', ');
|
|
58
68
|
const placeholders = keys.map(() => '?').join(', ');
|
|
59
69
|
const values = keys.map((k) => rowData[k]);
|
package/dist/storage/driver.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NodeFileDriver = exports.MemoryFileDriver = void 0;
|
|
4
|
+
const dynamic_js_1 = require("../utils/dynamic.js");
|
|
5
|
+
const NODE_FS_PROMISES_PKG = ['node:fs', 'promises'].join('/');
|
|
6
|
+
const NODE_PATH_PKG = ['node', 'path'].join(':');
|
|
4
7
|
/**
|
|
5
8
|
* Universal in-memory driver (ideal for tests, memory caches, and browser storage fallback).
|
|
6
9
|
*/
|
|
@@ -35,8 +38,12 @@ class NodeFileDriver {
|
|
|
35
38
|
}
|
|
36
39
|
async getFs() {
|
|
37
40
|
try {
|
|
38
|
-
const fs =
|
|
39
|
-
|
|
41
|
+
const fs = (0, dynamic_js_1.safeDynamicRequire)(NODE_FS_PROMISES_PKG) ??
|
|
42
|
+
(await (0, dynamic_js_1.safeDynamicImport)(NODE_FS_PROMISES_PKG));
|
|
43
|
+
const path = (0, dynamic_js_1.safeDynamicRequire)(NODE_PATH_PKG) ?? (await (0, dynamic_js_1.safeDynamicImport)(NODE_PATH_PKG));
|
|
44
|
+
if (!fs || !path) {
|
|
45
|
+
throw new Error('Node fs/path unavailable');
|
|
46
|
+
}
|
|
40
47
|
return { fs, path };
|
|
41
48
|
}
|
|
42
49
|
catch {
|
package/dist/storage/expo.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ExpoFileDriver = void 0;
|
|
4
4
|
exports.bytesToBase64 = bytesToBase64;
|
|
5
5
|
exports.base64ToBytes = base64ToBytes;
|
|
6
|
+
const dynamic_js_1 = require("../utils/dynamic.js");
|
|
7
|
+
const EXPO_FILE_SYSTEM_PKG = ['expo', 'file', 'system'].join('-');
|
|
6
8
|
/**
|
|
7
9
|
* Universal binary <-> base64 utilities compatible with Node, Browser, and React Native (Hermes).
|
|
8
10
|
*/
|
|
@@ -54,11 +56,13 @@ class ExpoFileDriver {
|
|
|
54
56
|
async resolveClasses() {
|
|
55
57
|
if (!this.FileClass || !this.DirectoryClass || !this.PathsObj) {
|
|
56
58
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
const mod = (0, dynamic_js_1.safeDynamicRequire)(EXPO_FILE_SYSTEM_PKG) ??
|
|
60
|
+
(await (0, dynamic_js_1.safeDynamicImport)(EXPO_FILE_SYSTEM_PKG));
|
|
61
|
+
if (mod) {
|
|
62
|
+
this.FileClass = this.FileClass ?? mod.File;
|
|
63
|
+
this.DirectoryClass = this.DirectoryClass ?? mod.Directory;
|
|
64
|
+
this.PathsObj = this.PathsObj ?? mod.Paths;
|
|
65
|
+
}
|
|
62
66
|
}
|
|
63
67
|
catch (error) {
|
|
64
68
|
if (!this.FileClass) {
|
package/dist/utils/dynamic.js
CHANGED
|
@@ -8,6 +8,23 @@ exports.safeDynamicImport = safeDynamicImport;
|
|
|
8
8
|
*/
|
|
9
9
|
function safeDynamicRequire(pkgName) {
|
|
10
10
|
try {
|
|
11
|
+
if (pkgName === 'react-native') {
|
|
12
|
+
return require('react-native');
|
|
13
|
+
}
|
|
14
|
+
if (pkgName === 'expo-sqlite') {
|
|
15
|
+
return require('expo-sqlite');
|
|
16
|
+
}
|
|
17
|
+
if (pkgName === 'expo-file-system') {
|
|
18
|
+
return require('expo-file-system');
|
|
19
|
+
}
|
|
20
|
+
if (pkgName === '@react-native-community/netinfo') {
|
|
21
|
+
return require('@react-native-community/netinfo');
|
|
22
|
+
}
|
|
23
|
+
// In Metro bundler (__r), calling require(variableString) triggers Metro's
|
|
24
|
+
// unknownModuleError console.error before throwing. Skip non-literal require in Metro.
|
|
25
|
+
if (typeof globalThis !== 'undefined' && typeof globalThis.__r === 'function') {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
11
28
|
const req = typeof __non_webpack_require__ !== 'undefined'
|
|
12
29
|
? __non_webpack_require__
|
|
13
30
|
: typeof require === 'function'
|
|
@@ -21,6 +38,13 @@ function safeDynamicRequire(pkgName) {
|
|
|
21
38
|
}
|
|
22
39
|
async function safeDynamicImport(pkgName) {
|
|
23
40
|
try {
|
|
41
|
+
const syncMod = safeDynamicRequire(pkgName);
|
|
42
|
+
if (syncMod !== undefined) {
|
|
43
|
+
return syncMod;
|
|
44
|
+
}
|
|
45
|
+
if (typeof globalThis !== 'undefined' && typeof globalThis.__r === 'function') {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
24
48
|
// Metro's AST worker rejects `import(dynamicVariable)` with "Invalid call at line ...: import(...)".
|
|
25
49
|
// Evaluating via new Function bypasses the bundler AST parser entirely while working in Node/browser.
|
|
26
50
|
const dynamicImport = new Function('specifier', 'return import(specifier);');
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "local-lite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Never let a lost connection break a promise. Local-first sync that faithfully keeps data safe until you're back online.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"local-lite": "bin/local-lite.mjs"
|
|
10
|
+
},
|
|
8
11
|
"files": [
|
|
12
|
+
"bin",
|
|
9
13
|
"dist",
|
|
10
14
|
"docs",
|
|
11
15
|
"skills",
|