@graypirate/tabula 1.0.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.
Files changed (71) hide show
  1. package/README.md +141 -0
  2. package/dist/API/create.d.ts +33 -0
  3. package/dist/API/create.js +91 -0
  4. package/dist/API/delete.d.ts +31 -0
  5. package/dist/API/delete.js +38 -0
  6. package/dist/API/index.d.ts +13 -0
  7. package/dist/API/index.js +9 -0
  8. package/dist/API/init.d.ts +3 -0
  9. package/dist/API/init.js +8 -0
  10. package/dist/API/read.d.ts +60 -0
  11. package/dist/API/read.js +95 -0
  12. package/dist/API/search.d.ts +4 -0
  13. package/dist/API/search.js +4 -0
  14. package/dist/API/types.d.ts +23 -0
  15. package/dist/API/types.js +0 -0
  16. package/dist/API/validation.d.ts +8 -0
  17. package/dist/API/validation.js +103 -0
  18. package/dist/API/write.d.ts +30 -0
  19. package/dist/API/write.js +90 -0
  20. package/dist/CLI/arguments.d.ts +45 -0
  21. package/dist/CLI/arguments.js +263 -0
  22. package/dist/CLI/dispatch.d.ts +3 -0
  23. package/dist/CLI/dispatch.js +143 -0
  24. package/dist/CLI/errors.d.ts +10 -0
  25. package/dist/CLI/errors.js +20 -0
  26. package/dist/CLI/index.d.ts +6 -0
  27. package/dist/CLI/index.js +70 -0
  28. package/dist/CLI/io.d.ts +6 -0
  29. package/dist/CLI/io.js +28 -0
  30. package/dist/CLI/json.d.ts +9 -0
  31. package/dist/CLI/json.js +42 -0
  32. package/dist/CLI/properties.d.ts +3 -0
  33. package/dist/CLI/properties.js +22 -0
  34. package/dist/index.d.ts +1 -0
  35. package/dist/index.js +1 -0
  36. package/dist/src/storage/db/blocks.d.ts +68 -0
  37. package/dist/src/storage/db/blocks.js +185 -0
  38. package/dist/src/storage/db/edges.d.ts +61 -0
  39. package/dist/src/storage/db/edges.js +306 -0
  40. package/dist/src/storage/db/init.d.ts +22 -0
  41. package/dist/src/storage/db/init.js +108 -0
  42. package/dist/src/storage/db/nodes.d.ts +34 -0
  43. package/dist/src/storage/db/nodes.js +91 -0
  44. package/dist/src/storage/db/objects.d.ts +55 -0
  45. package/dist/src/storage/db/objects.js +123 -0
  46. package/dist/src/storage/db/schema.sql +59 -0
  47. package/dist/src/storage/index.d.ts +47 -0
  48. package/dist/src/storage/index.js +315 -0
  49. package/dist/src/storage/types.d.ts +15 -0
  50. package/dist/src/storage/types.js +1 -0
  51. package/dist/src/types/block.d.ts +12 -0
  52. package/dist/src/types/block.js +0 -0
  53. package/dist/src/types/database.d.ts +6 -0
  54. package/dist/src/types/database.js +0 -0
  55. package/dist/src/types/graph.d.ts +11 -0
  56. package/dist/src/types/graph.js +0 -0
  57. package/dist/src/types/json.d.ts +7 -0
  58. package/dist/src/types/json.js +0 -0
  59. package/dist/src/types/object.d.ts +12 -0
  60. package/dist/src/types/object.js +0 -0
  61. package/dist/src/types/workspace.d.ts +6 -0
  62. package/dist/src/types/workspace.js +0 -0
  63. package/dist/src/utils/id.d.ts +6 -0
  64. package/dist/src/utils/id.js +18 -0
  65. package/dist/src/utils/yaml.d.ts +3 -0
  66. package/dist/src/utils/yaml.js +26 -0
  67. package/dist/src/workspace/index.d.ts +1 -0
  68. package/dist/src/workspace/index.js +1 -0
  69. package/dist/src/workspace/resolution.d.ts +20 -0
  70. package/dist/src/workspace/resolution.js +90 -0
  71. package/package.json +43 -0
@@ -0,0 +1,26 @@
1
+ import YAML from "yaml";
2
+ // HELPER - convert frontmatter to a dictionary
3
+ function frontmatterToDict(frontmatter) {
4
+ const result = {
5
+ id: frontmatter.id,
6
+ name: frontmatter.name,
7
+ };
8
+ if (frontmatter.properties !== undefined) {
9
+ result.properties = frontmatter.properties;
10
+ }
11
+ return result;
12
+ }
13
+ export function renderFrontmatter(frontmatter) {
14
+ const dict = frontmatterToDict(frontmatter);
15
+ return `---\n${YAML.stringify(dict)}---\n`;
16
+ }
17
+ export function parseFrontmatter(markdown) {
18
+ if (!markdown.startsWith("---")) {
19
+ throw new Error("Frontmatter must start with ---");
20
+ }
21
+ const end = markdown.indexOf("\n---", 3);
22
+ if (end === -1) {
23
+ throw new Error("Frontmatter must end with ---");
24
+ }
25
+ return YAML.parse(markdown.slice(4, end));
26
+ }
@@ -0,0 +1 @@
1
+ export * from "./resolution";
@@ -0,0 +1 @@
1
+ export * from "./resolution";
@@ -0,0 +1,20 @@
1
+ export declare class InvalidWorkspaceNameError extends Error {
2
+ readonly workspaceName: string;
3
+ readonly name = "InvalidWorkspaceNameError";
4
+ readonly details: {
5
+ allowed: string;
6
+ };
7
+ constructor(workspaceName: string);
8
+ }
9
+ export declare class WorkspaceNotFoundError extends Error {
10
+ readonly workspaceName: string;
11
+ readonly name = "WorkspaceNotFoundError";
12
+ constructor(workspaceName: string);
13
+ }
14
+ export declare function initializePackageStorage(): string;
15
+ export declare function validateWorkspaceName(name: string): void;
16
+ export declare function resolveWorkspaceDatabasePath(name: string): string;
17
+ export declare function deleteWorkspaceFiles(name: string): boolean;
18
+ export declare function resolveInitializedWorkspaceDatabasePath(name: string): string;
19
+ export declare function listWorkspaceNames(): string[];
20
+ export declare function workspaceDirectory(): string;
@@ -0,0 +1,90 @@
1
+ import { existsSync, mkdirSync, readdirSync, rmSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ const WorkspaceDirectoryName = ".tabula";
5
+ const DatabaseExtension = ".sqlite";
6
+ const WorkspaceNamePattern = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
7
+ export class InvalidWorkspaceNameError extends Error {
8
+ workspaceName;
9
+ name = "InvalidWorkspaceNameError";
10
+ details = {
11
+ allowed: "letters, numbers, underscores, hyphens, and dots; must not start with a dot",
12
+ };
13
+ constructor(workspaceName) {
14
+ super(`Invalid workspace name: ${workspaceName}`);
15
+ this.workspaceName = workspaceName;
16
+ }
17
+ }
18
+ export class WorkspaceNotFoundError extends Error {
19
+ workspaceName;
20
+ name = "WorkspaceNotFoundError";
21
+ constructor(workspaceName) {
22
+ super(`Workspace not found: ${workspaceName}`);
23
+ this.workspaceName = workspaceName;
24
+ }
25
+ }
26
+ export function initializePackageStorage() {
27
+ const directory = workspaceDirectory();
28
+ mkdirSync(directory, { recursive: true });
29
+ return directory;
30
+ }
31
+ export function validateWorkspaceName(name) {
32
+ if (!WorkspaceNamePattern.test(name)) {
33
+ throw new InvalidWorkspaceNameError(name);
34
+ }
35
+ }
36
+ export function resolveWorkspaceDatabasePath(name) {
37
+ validateWorkspaceName(name);
38
+ return join(workspaceDirectory(), `${name}${DatabaseExtension}`);
39
+ }
40
+ export function deleteWorkspaceFiles(name) {
41
+ const databasePath = resolveWorkspaceDatabasePath(name);
42
+ if (!existsSync(databasePath)) {
43
+ throw new WorkspaceNotFoundError(name);
44
+ }
45
+ let deleted = false;
46
+ for (const path of workspaceFilePaths(databasePath)) {
47
+ if (!existsSync(path)) {
48
+ continue;
49
+ }
50
+ rmSync(path, { force: true });
51
+ deleted = true;
52
+ }
53
+ return deleted;
54
+ }
55
+ export function resolveInitializedWorkspaceDatabasePath(name) {
56
+ validateWorkspaceName(name);
57
+ initializePackageStorage();
58
+ return resolveWorkspaceDatabasePath(name);
59
+ }
60
+ export function listWorkspaceNames() {
61
+ let entries;
62
+ try {
63
+ entries = readdirSync(workspaceDirectory(), { withFileTypes: true });
64
+ }
65
+ catch (error) {
66
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") {
67
+ return [];
68
+ }
69
+ throw error;
70
+ }
71
+ return entries
72
+ .filter((entry) => entry.isFile() && entry.name.endsWith(DatabaseExtension))
73
+ .map((entry) => entry.name.slice(0, -DatabaseExtension.length))
74
+ .filter(isValidWorkspaceName)
75
+ .sort();
76
+ }
77
+ export function workspaceDirectory() {
78
+ return join(process.env.HOME ?? homedir(), WorkspaceDirectoryName);
79
+ }
80
+ function isValidWorkspaceName(name) {
81
+ return WorkspaceNamePattern.test(name);
82
+ }
83
+ function workspaceFilePaths(databasePath) {
84
+ return [
85
+ databasePath,
86
+ `${databasePath}-wal`,
87
+ `${databasePath}-shm`,
88
+ `${databasePath}-journal`,
89
+ ];
90
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@graypirate/tabula",
3
+ "version": "1.0.0",
4
+ "description": "Flexible object-oriented relational storage for agents",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ }
15
+ },
16
+ "bin": {
17
+ "tabula": "dist/CLI/index.js"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "README.md"
22
+ ],
23
+ "scripts": {
24
+ "build": "rm -rf dist && tsc -p tsconfig.build.json && mkdir -p dist/src/storage/db && cp src/storage/db/schema.sql dist/src/storage/db/schema.sql && chmod 755 dist/CLI/index.js",
25
+ "prepublishOnly": "bun run typecheck && bun test && bun run build",
26
+ "test": "bun test",
27
+ "typecheck": "bunx tsc --noEmit"
28
+ },
29
+ "engines": {
30
+ "bun": ">=1.3.0"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "dependencies": {
36
+ "yaml": "^2.9.0"
37
+ },
38
+ "devDependencies": {
39
+ "@types/bun": "latest",
40
+ "@types/node": "^25.9.1",
41
+ "typescript": "^5"
42
+ }
43
+ }