create-syncular-app 0.1.3 → 0.2.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 (64) hide show
  1. package/README.md +70 -27
  2. package/dist/cli.d.ts +11 -0
  3. package/dist/cli.js +131 -179
  4. package/dist/constants.d.ts +40 -0
  5. package/dist/constants.js +46 -0
  6. package/dist/index.d.ts +3 -0
  7. package/dist/index.js +3 -0
  8. package/dist/scaffold.d.ts +44 -0
  9. package/dist/scaffold.js +106 -0
  10. package/package.json +22 -15
  11. package/src/cli.ts +174 -0
  12. package/src/constants.ts +53 -0
  13. package/src/index.ts +3 -0
  14. package/src/scaffold.ts +161 -0
  15. package/template/minimal/README.md +45 -0
  16. package/template/minimal/gitignore +5 -0
  17. package/template/minimal/migrations/0001_initial/up.sql +9 -0
  18. package/template/minimal/package.json +22 -0
  19. package/template/minimal/src/clients.ts +54 -0
  20. package/template/minimal/src/make-client.ts +26 -0
  21. package/template/minimal/src/server.ts +39 -0
  22. package/template/minimal/src/smoke.test.ts +70 -0
  23. package/template/minimal/src/syncular.generated.ts +66 -0
  24. package/template/minimal/syncular.ir.json +66 -0
  25. package/template/minimal/syncular.json +17 -0
  26. package/template/minimal/tsconfig.json +16 -0
  27. package/template/web/README.md +63 -0
  28. package/template/web/gitignore +5 -0
  29. package/template/web/migrations/0001_initial/up.sql +11 -0
  30. package/template/web/package.json +22 -0
  31. package/template/web/src/frontend/index.html +37 -0
  32. package/template/web/src/frontend/main.ts +191 -0
  33. package/template/web/src/frontend/worker.ts +9 -0
  34. package/template/web/src/server.ts +183 -0
  35. package/template/web/src/smoke.test.ts +91 -0
  36. package/template/web/src/syncular.generated.ts +74 -0
  37. package/template/web/syncular.ir.json +76 -0
  38. package/template/web/syncular.json +17 -0
  39. package/template/web/tsconfig.json +16 -0
  40. package/template/README.md +0 -122
  41. package/template/_gitignore +0 -5
  42. package/template/generated/kotlin/SyncularApp.kt +0 -1005
  43. package/template/generated/rust/diesel_tables.rs +0 -142
  44. package/template/generated/rust/migrations.rs +0 -32
  45. package/template/generated/rust/schema.rs +0 -15
  46. package/template/generated/rust/syncular.rs +0 -926
  47. package/template/generated/swift/SyncularApp.swift +0 -1191
  48. package/template/generated/syncular.codegen.json +0 -19
  49. package/template/index.html +0 -13
  50. package/template/migrations/0001_initial/down.sql +0 -1
  51. package/template/migrations/0001_initial/up.sql +0 -8
  52. package/template/package.json +0 -33
  53. package/template/scripts/dev.ts +0 -42
  54. package/template/src/app.tsx +0 -231
  55. package/template/src/client/syncular.ts +0 -61
  56. package/template/src/generated/syncular.generated.ts +0 -769
  57. package/template/src/generated/syncular.server.generated.ts +0 -512
  58. package/template/src/main.tsx +0 -5
  59. package/template/src/server/sync-server.ts +0 -129
  60. package/template/src/styles.css +0 -233
  61. package/template/syncular.app.ts +0 -23
  62. package/template/syncular.schema.json +0 -145
  63. package/template/tsconfig.json +0 -18
  64. package/template/vite.config.ts +0 -9
@@ -1,142 +0,0 @@
1
- // @generated by `cargo run --manifest-path rust/Cargo.toml -p syncular-codegen --`
2
- // Source: migrations/*.sql
3
-
4
- use super::schema;
5
- use diesel::prelude::*;
6
- use diesel::sqlite::SqliteConnection;
7
- use serde::{Deserialize, Serialize};
8
- use serde_json::Value;
9
- use syncular_client::app_schema::DieselTableAdapter;
10
- use syncular_client::error::{Result, SyncularError};
11
- use syncular_client::protocol::{ScopeValues, SyncChange};
12
-
13
- static TASKS_ADAPTER: TasksTableAdapter = TasksTableAdapter;
14
- static TABLE_ADAPTERS: [&dyn DieselTableAdapter; 1] = [&TASKS_ADAPTER];
15
-
16
- pub fn adapter_for(table: &str) -> Result<&'static dyn DieselTableAdapter> {
17
- TABLE_ADAPTERS
18
- .iter()
19
- .copied()
20
- .find(|adapter| adapter.name() == table)
21
- .ok_or_else(|| {
22
- SyncularError::codegen(format!("no Diesel table adapter registered for {table}"))
23
- })
24
- }
25
-
26
- #[derive(Debug, Clone, Queryable, Selectable, Insertable, Serialize, Deserialize)]
27
- #[diesel(table_name = schema::tasks)]
28
- pub struct TaskRow {
29
- pub id: String,
30
- pub title: String,
31
- pub completed: i32,
32
- pub user_id: String,
33
- pub created_at: i64,
34
- pub server_version: i64,
35
- }
36
-
37
- struct TasksTableAdapter;
38
-
39
- impl DieselTableAdapter for TasksTableAdapter {
40
- fn name(&self) -> &'static str {
41
- "tasks"
42
- }
43
-
44
- fn list_rows_json(&self, conn: &mut SqliteConnection) -> Result<Vec<Value>> {
45
- use schema::tasks::dsl as t;
46
-
47
- let rows: Vec<TaskRow> = t::tasks.select(TaskRow::as_select()).load(conn)?;
48
- rows.into_iter()
49
- .map(serde_json::to_value)
50
- .collect::<serde_json::Result<Vec<_>>>()
51
- .map_err(Into::into)
52
- }
53
-
54
- fn clear_for_scopes(&self, conn: &mut SqliteConnection, scopes: &ScopeValues) -> Result<()> {
55
- use schema::tasks::dsl as t;
56
-
57
- let scope_0 = scopes.get("user_id").and_then(Value::as_str);
58
-
59
- if scope_0.is_some() {
60
- diesel::delete(t::tasks.filter(t::user_id.eq(scope_0.expect("scope checked"))))
61
- .execute(conn)?;
62
- } else {
63
- diesel::delete(t::tasks).execute(conn)?;
64
- }
65
-
66
- Ok(())
67
- }
68
-
69
- fn upsert_row(
70
- &self,
71
- conn: &mut SqliteConnection,
72
- row: &Value,
73
- fallback_version: Option<i64>,
74
- ) -> Result<()> {
75
- use schema::tasks::dsl as t;
76
-
77
- let obj = row.as_object().ok_or_else(|| {
78
- SyncularError::protocol_message(format!("row is not an object: {row}"))
79
- })?;
80
- let row = TaskRow {
81
- id: obj
82
- .get("id")
83
- .and_then(Value::as_str)
84
- .ok_or_else(|| SyncularError::protocol_message("id missing"))?
85
- .to_string(),
86
- title: obj
87
- .get("title")
88
- .and_then(Value::as_str)
89
- .unwrap_or("")
90
- .to_string(),
91
- completed: obj.get("completed").and_then(Value::as_i64).unwrap_or(0) as i32,
92
- user_id: obj
93
- .get("user_id")
94
- .and_then(Value::as_str)
95
- .unwrap_or("")
96
- .to_string(),
97
- created_at: obj.get("created_at").and_then(Value::as_i64).unwrap_or(0),
98
- server_version: fallback_version
99
- .or_else(|| obj.get("server_version").and_then(Value::as_i64))
100
- .unwrap_or(0),
101
- };
102
-
103
- diesel::insert_into(t::tasks)
104
- .values(&row)
105
- .on_conflict(t::id)
106
- .do_update()
107
- .set((
108
- t::title.eq(&row.title),
109
- t::completed.eq(&row.completed),
110
- t::user_id.eq(&row.user_id),
111
- t::created_at.eq(&row.created_at),
112
- t::server_version.eq(&row.server_version),
113
- ))
114
- .execute(conn)?;
115
-
116
- Ok(())
117
- }
118
-
119
- fn apply_change(&self, conn: &mut SqliteConnection, change: &SyncChange) -> Result<()> {
120
- use schema::tasks::dsl as t;
121
-
122
- if change.table != "tasks" {
123
- return Err(SyncularError::codegen(format!(
124
- "adapter cannot apply change for table {}",
125
- change.table
126
- )));
127
- }
128
-
129
- if change.op == "delete" {
130
- diesel::delete(t::tasks.filter(t::id.eq(&change.row_id))).execute(conn)?;
131
- return Ok(());
132
- }
133
-
134
- let row = change.row_json.as_ref().ok_or_else(|| {
135
- SyncularError::protocol_message(format!(
136
- "upsert change missing row_json for {}",
137
- change.row_id
138
- ))
139
- })?;
140
- self.upsert_row(conn, row, change.row_version)
141
- }
142
- }
@@ -1,32 +0,0 @@
1
- // @generated by `cargo run --manifest-path rust/Cargo.toml -p syncular-codegen --`
2
- // Source: migrations/*.sql
3
-
4
- use syncular_client::app_schema::current_schema_version as latest_schema_version;
5
- pub use syncular_client::app_schema::{checksum, split_sql_statements, EmbeddedMigration};
6
-
7
- pub const MIGRATIONS: &[EmbeddedMigration] = &[
8
- EmbeddedMigration {
9
- version: "0001",
10
- schema_version: 1,
11
- name: "initial",
12
- up_sql: "CREATE TABLE IF NOT EXISTS tasks (\n id TEXT PRIMARY KEY,\n title TEXT NOT NULL,\n completed INTEGER NOT NULL DEFAULT 0,\n user_id TEXT NOT NULL,\n created_at BIGINT NOT NULL DEFAULT 0,\n server_version BIGINT NOT NULL DEFAULT 0\n) WITHOUT ROWID;",
13
- },
14
- ];
15
-
16
- pub const LOCAL_BASE_TABLE_SETUP_SQL: &[&str] = &[
17
- "CREATE TABLE IF NOT EXISTS \"tasks\" (\n \"id\" TEXT PRIMARY KEY,\n \"title\" TEXT NOT NULL,\n \"completed\" INTEGER NOT NULL DEFAULT 0,\n \"user_id\" TEXT NOT NULL,\n \"created_at\" INTEGER NOT NULL DEFAULT 0,\n \"server_version\" INTEGER NOT NULL DEFAULT 0\n) WITHOUT ROWID",
18
- ];
19
-
20
- #[derive(Debug, Clone, Copy, PartialEq, Eq)]
21
- pub struct LocalReadModelSql {
22
- pub name: &'static str,
23
- pub output_table: &'static str,
24
- pub setup_sql: &'static [&'static str],
25
- pub rebuild_sql: &'static [&'static str],
26
- }
27
-
28
- pub const LOCAL_READ_MODELS: &[LocalReadModelSql] = &[];
29
-
30
- pub fn current_schema_version() -> i32 {
31
- latest_schema_version(MIGRATIONS)
32
- }
@@ -1,15 +0,0 @@
1
- // @generated by `cargo run --manifest-path rust/Cargo.toml -p syncular-codegen --`
2
- // Source: migrations/*.sql
3
-
4
- diesel::table! {
5
- tasks (id) {
6
- id -> Text,
7
- title -> Text,
8
- completed -> Integer,
9
- user_id -> Text,
10
- created_at -> BigInt,
11
- server_version -> BigInt,
12
- }
13
- }
14
-
15
- diesel::allow_tables_to_appear_in_same_query!(tasks,);