spacetimedb 0.0.2 → 0.0.3
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/browser/react/index.mjs.map +1 -1
- package/dist/index.browser.mjs +18 -4
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.cjs +18 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +18 -16
- package/dist/index.mjs.map +1 -1
- package/dist/lib/algebraic_type.d.ts +115 -0
- package/dist/lib/algebraic_type.d.ts.map +1 -0
- package/dist/lib/algebraic_value.d.ts +6 -0
- package/dist/lib/algebraic_value.d.ts.map +1 -0
- package/dist/lib/autogen/algebraic_type_type.d.ts +64 -0
- package/dist/lib/autogen/algebraic_type_type.d.ts.map +1 -0
- package/dist/lib/autogen/algebraic_type_variants.d.ts +68 -0
- package/dist/lib/autogen/algebraic_type_variants.d.ts.map +1 -0
- package/dist/lib/autogen/index_type_type.d.ts +16 -0
- package/dist/lib/autogen/index_type_type.d.ts.map +1 -0
- package/dist/lib/autogen/index_type_variants.d.ts +7 -0
- package/dist/lib/autogen/index_type_variants.d.ts.map +1 -0
- package/dist/lib/autogen/lifecycle_type.d.ts +19 -0
- package/dist/lib/autogen/lifecycle_type.d.ts.map +1 -0
- package/dist/lib/autogen/lifecycle_variants.d.ts +10 -0
- package/dist/lib/autogen/lifecycle_variants.d.ts.map +1 -0
- package/dist/lib/autogen/misc_module_export_type.d.ts +12 -0
- package/dist/lib/autogen/misc_module_export_type.d.ts.map +1 -0
- package/dist/lib/autogen/misc_module_export_variants.d.ts +6 -0
- package/dist/lib/autogen/misc_module_export_variants.d.ts.map +1 -0
- package/dist/lib/autogen/product_type_element_type.d.ts +20 -0
- package/dist/lib/autogen/product_type_element_type.d.ts.map +1 -0
- package/dist/lib/autogen/product_type_type.d.ts +19 -0
- package/dist/lib/autogen/product_type_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_column_def_v_8_type.d.ts +20 -0
- package/dist/lib/autogen/raw_column_def_v_8_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_column_default_value_v_9_type.d.ts +20 -0
- package/dist/lib/autogen/raw_column_default_value_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_constraint_data_v_9_type.d.ts +12 -0
- package/dist/lib/autogen/raw_constraint_data_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_constraint_data_v_9_variants.d.ts +6 -0
- package/dist/lib/autogen/raw_constraint_data_v_9_variants.d.ts.map +1 -0
- package/dist/lib/autogen/raw_constraint_def_v_8_type.d.ts +20 -0
- package/dist/lib/autogen/raw_constraint_def_v_8_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_constraint_def_v_9_type.d.ts +20 -0
- package/dist/lib/autogen/raw_constraint_def_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_index_algorithm_type.d.ts +13 -0
- package/dist/lib/autogen/raw_index_algorithm_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_index_algorithm_variants.d.ts +13 -0
- package/dist/lib/autogen/raw_index_algorithm_variants.d.ts.map +1 -0
- package/dist/lib/autogen/raw_index_def_v_8_type.d.ts +22 -0
- package/dist/lib/autogen/raw_index_def_v_8_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_index_def_v_9_type.d.ts +21 -0
- package/dist/lib/autogen/raw_index_def_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_misc_module_export_v_9_type.d.ts +12 -0
- package/dist/lib/autogen/raw_misc_module_export_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_misc_module_export_v_9_variants.d.ts +6 -0
- package/dist/lib/autogen/raw_misc_module_export_v_9_variants.d.ts.map +1 -0
- package/dist/lib/autogen/raw_module_def_type.d.ts +14 -0
- package/dist/lib/autogen/raw_module_def_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_module_def_v_8_type.d.ts +25 -0
- package/dist/lib/autogen/raw_module_def_v_8_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_module_def_v_9_type.d.ts +29 -0
- package/dist/lib/autogen/raw_module_def_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_module_def_variants.d.ts +11 -0
- package/dist/lib/autogen/raw_module_def_variants.d.ts.map +1 -0
- package/dist/lib/autogen/raw_reducer_def_v_9_type.d.ts +22 -0
- package/dist/lib/autogen/raw_reducer_def_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_row_level_security_def_v_9_type.d.ts +18 -0
- package/dist/lib/autogen/raw_row_level_security_def_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_schedule_def_v_9_type.d.ts +20 -0
- package/dist/lib/autogen/raw_schedule_def_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_scoped_type_name_v_9_type.d.ts +19 -0
- package/dist/lib/autogen/raw_scoped_type_name_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_sequence_def_v_8_type.d.ts +24 -0
- package/dist/lib/autogen/raw_sequence_def_v_8_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_sequence_def_v_9_type.d.ts +23 -0
- package/dist/lib/autogen/raw_sequence_def_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_table_def_v_8_type.d.ts +29 -0
- package/dist/lib/autogen/raw_table_def_v_8_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_table_def_v_9_type.d.ts +32 -0
- package/dist/lib/autogen/raw_table_def_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_type_def_v_9_type.d.ts +21 -0
- package/dist/lib/autogen/raw_type_def_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/raw_unique_constraint_data_v_9_type.d.ts +18 -0
- package/dist/lib/autogen/raw_unique_constraint_data_v_9_type.d.ts.map +1 -0
- package/dist/lib/autogen/reducer_def_type.d.ts +20 -0
- package/dist/lib/autogen/reducer_def_type.d.ts.map +1 -0
- package/dist/lib/autogen/sum_type_type.d.ts +19 -0
- package/dist/lib/autogen/sum_type_type.d.ts.map +1 -0
- package/dist/lib/autogen/sum_type_variant_type.d.ts +20 -0
- package/dist/lib/autogen/sum_type_variant_type.d.ts.map +1 -0
- package/dist/lib/autogen/table_access_type.d.ts +16 -0
- package/dist/lib/autogen/table_access_type.d.ts.map +1 -0
- package/dist/lib/autogen/table_access_variants.d.ts +7 -0
- package/dist/lib/autogen/table_access_variants.d.ts.map +1 -0
- package/dist/lib/autogen/table_desc_type.d.ts +20 -0
- package/dist/lib/autogen/table_desc_type.d.ts.map +1 -0
- package/dist/lib/autogen/table_type_type.d.ts +16 -0
- package/dist/lib/autogen/table_type_type.d.ts.map +1 -0
- package/dist/lib/autogen/table_type_variants.d.ts +7 -0
- package/dist/lib/autogen/table_type_variants.d.ts.map +1 -0
- package/dist/lib/autogen/type_alias_type.d.ts +19 -0
- package/dist/lib/autogen/type_alias_type.d.ts.map +1 -0
- package/dist/lib/autogen/typespace_type.d.ts +19 -0
- package/dist/lib/autogen/typespace_type.d.ts.map +1 -0
- package/dist/lib/binary_reader.d.ts +25 -0
- package/dist/lib/binary_reader.d.ts.map +1 -0
- package/dist/lib/binary_writer.d.ts +25 -0
- package/dist/lib/binary_writer.d.ts.map +1 -0
- package/dist/lib/connection_id.d.ts +37 -0
- package/dist/lib/connection_id.d.ts.map +1 -0
- package/dist/lib/identity.d.ts +39 -0
- package/dist/lib/identity.d.ts.map +1 -0
- package/dist/lib/schedule_at.d.ts +23 -0
- package/dist/lib/schedule_at.d.ts.map +1 -0
- package/dist/lib/time_duration.d.ts +18 -0
- package/dist/lib/time_duration.d.ts.map +1 -0
- package/dist/lib/timestamp.d.ts +35 -0
- package/dist/lib/timestamp.d.ts.map +1 -0
- package/dist/lib/utils.d.ts +13 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/min/index.browser.mjs +1 -1
- package/dist/min/index.browser.mjs.map +1 -1
- package/dist/min/react/index.mjs.map +1 -1
- package/dist/min/sdk/index.browser.mjs +1 -1
- package/dist/min/sdk/index.browser.mjs.map +1 -1
- package/dist/react/SpacetimeDBProvider.d.ts +8 -0
- package/dist/react/SpacetimeDBProvider.d.ts.map +1 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/useSpacetimeDB.d.ts +5 -0
- package/dist/react/useSpacetimeDB.d.ts.map +1 -0
- package/dist/react/useTable.d.ts +120 -0
- package/dist/react/useTable.d.ts.map +1 -0
- package/dist/sdk/client_api/bsatn_row_list_type.d.ts +20 -0
- package/dist/sdk/client_api/bsatn_row_list_type.d.ts.map +1 -0
- package/dist/sdk/client_api/call_reducer_type.d.ts +21 -0
- package/dist/sdk/client_api/call_reducer_type.d.ts.map +1 -0
- package/dist/sdk/client_api/client_message_type.d.ts +24 -0
- package/dist/sdk/client_api/client_message_type.d.ts.map +1 -0
- package/dist/sdk/client_api/client_message_variants.d.ts +36 -0
- package/dist/sdk/client_api/client_message_variants.d.ts.map +1 -0
- package/dist/sdk/client_api/compressable_query_update_type.d.ts +14 -0
- package/dist/sdk/client_api/compressable_query_update_type.d.ts.map +1 -0
- package/dist/sdk/client_api/compressable_query_update_variants.d.ts +14 -0
- package/dist/sdk/client_api/compressable_query_update_variants.d.ts.map +1 -0
- package/dist/sdk/client_api/database_update_type.d.ts +19 -0
- package/dist/sdk/client_api/database_update_type.d.ts.map +1 -0
- package/dist/sdk/client_api/energy_quanta_type.d.ts +18 -0
- package/dist/sdk/client_api/energy_quanta_type.d.ts.map +1 -0
- package/dist/sdk/client_api/identity_token_type.d.ts +20 -0
- package/dist/sdk/client_api/identity_token_type.d.ts.map +1 -0
- package/dist/sdk/client_api/index.d.ts +86 -0
- package/dist/sdk/client_api/index.d.ts.map +1 -0
- package/dist/sdk/client_api/initial_subscription_type.d.ts +21 -0
- package/dist/sdk/client_api/initial_subscription_type.d.ts.map +1 -0
- package/dist/sdk/client_api/one_off_query_response_type.d.ts +22 -0
- package/dist/sdk/client_api/one_off_query_response_type.d.ts.map +1 -0
- package/dist/sdk/client_api/one_off_query_type.d.ts +19 -0
- package/dist/sdk/client_api/one_off_query_type.d.ts.map +1 -0
- package/dist/sdk/client_api/one_off_table_type.d.ts +20 -0
- package/dist/sdk/client_api/one_off_table_type.d.ts.map +1 -0
- package/dist/sdk/client_api/query_id_type.d.ts +18 -0
- package/dist/sdk/client_api/query_id_type.d.ts.map +1 -0
- package/dist/sdk/client_api/query_update_type.d.ts +20 -0
- package/dist/sdk/client_api/query_update_type.d.ts.map +1 -0
- package/dist/sdk/client_api/reducer_call_info_type.d.ts +21 -0
- package/dist/sdk/client_api/reducer_call_info_type.d.ts.map +1 -0
- package/dist/sdk/client_api/row_size_hint_type.d.ts +12 -0
- package/dist/sdk/client_api/row_size_hint_type.d.ts.map +1 -0
- package/dist/sdk/client_api/row_size_hint_variants.d.ts +9 -0
- package/dist/sdk/client_api/row_size_hint_variants.d.ts.map +1 -0
- package/dist/sdk/client_api/server_message_type.d.ts +30 -0
- package/dist/sdk/client_api/server_message_type.d.ts.map +1 -0
- package/dist/sdk/client_api/server_message_variants.d.ts +51 -0
- package/dist/sdk/client_api/server_message_variants.d.ts.map +1 -0
- package/dist/sdk/client_api/subscribe_applied_type.d.ts +23 -0
- package/dist/sdk/client_api/subscribe_applied_type.d.ts.map +1 -0
- package/dist/sdk/client_api/subscribe_multi_applied_type.d.ts +23 -0
- package/dist/sdk/client_api/subscribe_multi_applied_type.d.ts.map +1 -0
- package/dist/sdk/client_api/subscribe_multi_type.d.ts +21 -0
- package/dist/sdk/client_api/subscribe_multi_type.d.ts.map +1 -0
- package/dist/sdk/client_api/subscribe_rows_type.d.ts +21 -0
- package/dist/sdk/client_api/subscribe_rows_type.d.ts.map +1 -0
- package/dist/sdk/client_api/subscribe_single_type.d.ts +21 -0
- package/dist/sdk/client_api/subscribe_single_type.d.ts.map +1 -0
- package/dist/sdk/client_api/subscribe_type.d.ts +19 -0
- package/dist/sdk/client_api/subscribe_type.d.ts.map +1 -0
- package/dist/sdk/client_api/subscription_error_type.d.ts +22 -0
- package/dist/sdk/client_api/subscription_error_type.d.ts.map +1 -0
- package/dist/sdk/client_api/table_update_type.d.ts +22 -0
- package/dist/sdk/client_api/table_update_type.d.ts.map +1 -0
- package/dist/sdk/client_api/transaction_update_light_type.d.ts +20 -0
- package/dist/sdk/client_api/transaction_update_light_type.d.ts.map +1 -0
- package/dist/sdk/client_api/transaction_update_type.d.ts +27 -0
- package/dist/sdk/client_api/transaction_update_type.d.ts.map +1 -0
- package/dist/sdk/client_api/unsubscribe_applied_type.d.ts +23 -0
- package/dist/sdk/client_api/unsubscribe_applied_type.d.ts.map +1 -0
- package/dist/sdk/client_api/unsubscribe_multi_applied_type.d.ts +23 -0
- package/dist/sdk/client_api/unsubscribe_multi_applied_type.d.ts.map +1 -0
- package/dist/sdk/client_api/unsubscribe_multi_type.d.ts +20 -0
- package/dist/sdk/client_api/unsubscribe_multi_type.d.ts.map +1 -0
- package/dist/sdk/client_api/unsubscribe_type.d.ts +20 -0
- package/dist/sdk/client_api/unsubscribe_type.d.ts.map +1 -0
- package/dist/sdk/client_api/update_status_type.d.ts +16 -0
- package/dist/sdk/client_api/update_status_type.d.ts.map +1 -0
- package/dist/sdk/client_api/update_status_variants.d.ts +13 -0
- package/dist/sdk/client_api/update_status_variants.d.ts.map +1 -0
- package/dist/sdk/client_cache.d.ts +17 -0
- package/dist/sdk/client_cache.d.ts.map +1 -0
- package/dist/sdk/db_connection_builder.d.ts +145 -0
- package/dist/sdk/db_connection_builder.d.ts.map +1 -0
- package/dist/sdk/db_connection_impl.d.ts +102 -0
- package/dist/sdk/db_connection_impl.d.ts.map +1 -0
- package/dist/sdk/db_context.d.ts +25 -0
- package/dist/sdk/db_context.d.ts.map +1 -0
- package/dist/sdk/decompress.d.ts +2 -0
- package/dist/sdk/decompress.d.ts.map +1 -0
- package/dist/sdk/event.d.ts +15 -0
- package/dist/sdk/event.d.ts.map +1 -0
- package/dist/sdk/event_context.d.ts +18 -0
- package/dist/sdk/event_context.d.ts.map +1 -0
- package/dist/sdk/event_emitter.d.ts +7 -0
- package/dist/sdk/event_emitter.d.ts.map +1 -0
- package/dist/sdk/index.browser.mjs +18 -4
- package/dist/sdk/index.browser.mjs.map +1 -1
- package/dist/sdk/index.cjs +18 -16
- package/dist/sdk/index.cjs.map +1 -1
- package/dist/sdk/index.d.ts +4 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.mjs +18 -16
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/sdk/json_api.d.ts +40 -0
- package/dist/sdk/json_api.d.ts.map +1 -0
- package/dist/sdk/logger.d.ts +4 -0
- package/dist/sdk/logger.d.ts.map +1 -0
- package/dist/sdk/message_types.d.ts +50 -0
- package/dist/sdk/message_types.d.ts.map +1 -0
- package/dist/sdk/reducer_event.d.ts +42 -0
- package/dist/sdk/reducer_event.d.ts.map +1 -0
- package/dist/sdk/spacetime_module.d.ts +31 -0
- package/dist/sdk/spacetime_module.d.ts.map +1 -0
- package/dist/sdk/subscription_builder_impl.d.ts +126 -0
- package/dist/sdk/subscription_builder_impl.d.ts.map +1 -0
- package/dist/sdk/table_cache.d.ts +111 -0
- package/dist/sdk/table_cache.d.ts.map +1 -0
- package/dist/sdk/version.d.ts +18 -0
- package/dist/sdk/version.d.ts.map +1 -0
- package/dist/sdk/websocket_decompress_adapter.d.ts +21 -0
- package/dist/sdk/websocket_decompress_adapter.d.ts.map +1 -0
- package/dist/sdk/websocket_test_adapter.d.ts +22 -0
- package/dist/sdk/websocket_test_adapter.d.ts.map +1 -0
- package/dist/sdk/ws.d.ts +2 -0
- package/dist/sdk/ws.d.ts.map +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/type_builders.d.ts +656 -0
- package/dist/server/type_builders.d.ts.map +1 -0
- package/dist/server/type_builders.test-d.d.ts +2 -0
- package/dist/server/type_builders.test-d.d.ts.map +1 -0
- package/dist/server/type_util.d.ts +18 -0
- package/dist/server/type_util.d.ts.map +1 -0
- package/package.json +30 -27
- package/src/react/SpacetimeDBProvider.ts +4 -1
- package/src/react/useSpacetimeDB.ts +1 -1
- package/src/react/useTable.ts +1 -1
- package/src/sdk/db_connection_builder.ts +1 -1
- package/src/sdk/db_connection_impl.ts +6 -6
- package/src/sdk/message_types.ts +3 -3
- package/src/sdk/reducer_event.ts +3 -3
- package/src/sdk/spacetime_module.ts +1 -1
- package/src/sdk/table_cache.ts +1 -1
- package/src/sdk/websocket_decompress_adapter.ts +2 -30
- package/src/sdk/websocket_test_adapter.ts +1 -1
- package/src/sdk/ws.ts +24 -0
- package/LICENSE.txt +0 -759
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DbConnectionBuilder, type DbConnectionImpl } from '../sdk/db_connection_impl';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export interface SpacetimeDBProviderProps<DbConnection extends DbConnectionImpl, ErrorContext, SubscriptionEventContext> {
|
|
4
|
+
connectionBuilder: DbConnectionBuilder<DbConnection, ErrorContext, SubscriptionEventContext>;
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare function SpacetimeDBProvider<DbConnection extends DbConnectionImpl, ErrorContext, SubscriptionEventContext>({ connectionBuilder, children, }: SpacetimeDBProviderProps<DbConnection, ErrorContext, SubscriptionEventContext>): React.JSX.Element;
|
|
8
|
+
//# sourceMappingURL=SpacetimeDBProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SpacetimeDBProvider.d.ts","sourceRoot":"","sources":["../../src/react/SpacetimeDBProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,KAAK,gBAAgB,EACtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,WAAW,wBAAwB,CACvC,YAAY,SAAS,gBAAgB,EACrC,YAAY,EACZ,wBAAwB;IAExB,iBAAiB,EAAE,mBAAmB,CACpC,YAAY,EACZ,YAAY,EACZ,wBAAwB,CACzB,CAAC;IACF,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,mBAAmB,CACjC,YAAY,SAAS,gBAAgB,EACrC,YAAY,EACZ,wBAAwB,EACxB,EACA,iBAAiB,EACjB,QAAQ,GACT,EAAE,wBAAwB,CACzB,YAAY,EACZ,YAAY,EACZ,wBAAwB,CACzB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAMpB"}
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/useSpacetimeDB.ts","../../src/react/SpacetimeDBProvider.ts","../../src/react/useTable.ts"],"names":["createContext","useContext","React","where","useState","useRef","useCallback","useEffect","useSyncExternalStore"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,kBAAA,GACXA,oBAA4C,MAAS,CAAA;AAIhD,SAAS,cAAA,GAEE;AAChB,EAAA,MAAM,OAAA,GAAUC,iBAAW,kBAAkB,CAAA;AAC7C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;ACDO,SAAS,mBAAA,CAId;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAA,EAIsB;AACpB,EAAA,OAAaC,gBAAA,CAAA,aAAA;AAAA,IACX,kBAAA,CAAmB,QAAA;AAAA,IACnB,EAAE,KAAA,EAAO,iBAAA,CAAkB,KAAA,EAAM,EAAE;AAAA;AAAA,IACnC;AAAA,GACF;AACF;ACXO,IAAM,EAAA,GAAK,CAChB,GAAA,EACA,KAAA,MACkB,EAAE,IAAA,EAAM,IAAA,EAAM,KAAK,KAAA,EAAM;AA4CtC,SA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A;AAC7B,QAAA,KAAA,CAAM,eAAe,QAAQ,CAAA;AAC7B,QAAA,KAAA,CAAM,iBAAiB,QAAQ,CAAA;AAAA,MACjC,CAAA;AAAA,IACF,CAAA;AAAA;AAAA,IAEA;AAAA,MACE,MAAA;AAAA,MACA,SAAA;AAAA,MACA,QAAA;AAAA,MACA,SAAA,EAAW,QAAA;AAAA,MACX,SAAA,EAAW,QAAA;AAAA,MACX,SAAA,EAAW;AAAA;AACb,GACF;AAEA,EAAA,MAAM,WAAA,GAAcA,kBAAY,MAAyB;AACvD,IAAA,IAAI,CAAC,gBAAgB,OAAA,EAAS;AAC5B,MAAA,eAAA,CAAgB,UAAU,eAAA,EAAgB;AAAA,IAC5C;AACA,IAAA,OAAO,eAAA,CAAgB,OAAA;AAAA,EACzB,CAAA,EAAG,CAAC,eAAe,CAAC,CAAA;AAGpB,EAAA,OAAOE,0BAAA,CAAqB,SAAA,EAAW,WAAA,EAAa,WAAW,CAAA;AACjE","file":"index.cjs","sourcesContent":["import { createContext, useContext, type Context } from 'react';\nimport type { DbConnectionImpl } from '../index';\n\nexport const SpacetimeDBContext: Context<DbConnectionImpl | undefined> =\n createContext<DbConnectionImpl | undefined>(undefined);\n\n// Throws an error if used outside of a SpacetimeDBProvider\n// Error is caught by other hooks like useTable so they can provide better error messages\nexport function useSpacetimeDB<\n DbConnection extends DbConnectionImpl,\n>(): DbConnection {\n const context = useContext(SpacetimeDBContext) as DbConnection | undefined;\n if (!context) {\n throw new Error(\n 'useSpacetimeDB must be used within a SpacetimeDBProvider component. Did you forget to add a `SpacetimeDBProvider` to your component tree?'\n );\n }\n return context;\n}\n","import { DbConnectionBuilder, type DbConnectionImpl } from '../index';\nimport * as React from 'react';\nimport { SpacetimeDBContext } from './useSpacetimeDB';\n\nexport interface SpacetimeDBProviderProps<\n DbConnection extends DbConnectionImpl,\n ErrorContext,\n SubscriptionEventContext,\n> {\n connectionBuilder: DbConnectionBuilder<\n DbConnection,\n ErrorContext,\n SubscriptionEventContext\n >;\n children?: React.ReactNode;\n}\n\nexport function SpacetimeDBProvider<\n DbConnection extends DbConnectionImpl,\n ErrorContext,\n SubscriptionEventContext,\n>({\n connectionBuilder,\n children,\n}: SpacetimeDBProviderProps<\n DbConnection,\n ErrorContext,\n SubscriptionEventContext\n>): React.JSX.Element {\n return React.createElement(\n SpacetimeDBContext.Provider,\n { value: connectionBuilder.build() }, // May need to modify this to do it lazily in server-side rendering\n children\n );\n}\n","import {\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { useSpacetimeDB } from './useSpacetimeDB';\nimport { DbConnectionImpl, TableCache } from '../sdk';\n\nexport interface UseQueryCallbacks<RowType> {\n onInsert?: (row: RowType) => void;\n onDelete?: (row: RowType) => void;\n onUpdate?: (oldRow: RowType, newRow: RowType) => void;\n}\n\nexport type Value = string | number | boolean;\n\nexport type Expr<Column extends string> =\n | { type: 'eq'; key: Column; value: Value }\n | { type: 'and'; children: Expr<Column>[] }\n | { type: 'or'; children: Expr<Column>[] };\n\nexport const eq = <Column extends string>(\n key: Column,\n value: Value\n): Expr<Column> => ({ type: 'eq', key, value });\n\nexport const and = <Column extends string>(\n ...children: Expr<Column>[]\n): Expr<Column> => {\n const flat: Expr<Column>[] = [];\n for (const c of children) {\n if (!c) continue;\n if (c.type === 'and') flat.push(...c.children);\n else flat.push(c);\n }\n const pruned = flat.filter(Boolean);\n if (pruned.length === 0) return { type: 'and', children: [] };\n if (pruned.length === 1) return pruned[0];\n return { type: 'and', children: pruned };\n};\n\nexport const or = <Column extends string>(\n ...children: Expr<Column>[]\n): Expr<Column> => {\n const flat: Expr<Column>[] = [];\n for (const c of children) {\n if (!c) continue;\n if (c.type === 'or') flat.push(...c.children);\n else flat.push(c);\n }\n const pruned = flat.filter(Boolean);\n if (pruned.length === 0) return { type: 'or', children: [] };\n if (pruned.length === 1) return pruned[0];\n return { type: 'or', children: pruned };\n};\n\nexport const isEq = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'eq' }> => e.type === 'eq';\nexport const isAnd = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'and' }> => e.type === 'and';\nexport const isOr = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'or' }> => e.type === 'or';\n\ntype RecordLike<Column extends string> = Record<Column, unknown>;\n\nexport function evaluate<Column extends string>(\n expr: Expr<Column>,\n row: RecordLike<Column>\n): boolean {\n switch (expr.type) {\n case 'eq': {\n const v = row[expr.key];\n if (\n typeof v === 'string' ||\n typeof v === 'number' ||\n typeof v === 'boolean'\n ) {\n return v === expr.value;\n }\n return false;\n }\n case 'and':\n return (\n expr.children.length === 0 || expr.children.every(c => evaluate(c, row))\n );\n case 'or':\n return (\n expr.children.length !== 0 && expr.children.some(c => evaluate(c, row))\n );\n }\n}\n\nfunction formatValue(v: Value): string {\n switch (typeof v) {\n case 'string':\n return `'${v.replace(/'/g, \"''\")}'`;\n case 'number':\n return Number.isFinite(v) ? String(v) : `'${String(v)}'`;\n case 'boolean':\n return v ? 'TRUE' : 'FALSE';\n }\n}\n\nfunction escapeIdent(id: string): string {\n if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(id)) return id;\n return `\"${id.replace(/\"/g, '\"\"')}\"`;\n}\n\nfunction parenthesize(s: string): string {\n if (!s.includes(' AND ') && !s.includes(' OR ')) return s;\n return `(${s})`;\n}\n\nexport function toString<Column extends string>(expr: Expr<Column>): string {\n switch (expr.type) {\n case 'eq':\n return `${escapeIdent(expr.key)} = ${formatValue(expr.value)}`;\n case 'and':\n return parenthesize(expr.children.map(toString).join(' AND '));\n case 'or':\n return parenthesize(expr.children.map(toString).join(' OR '));\n }\n}\n\n/**\n * This is just the identity function to make things look like SQL.\n * @param expr\n * @returns\n */\nexport function where<Column extends string>(expr: Expr<Column>): Expr<Column> {\n return expr;\n}\n\ntype Snapshot<RowType> = {\n readonly rows: readonly RowType[];\n readonly state: 'loading' | 'ready';\n};\n\ntype MembershipChange = 'enter' | 'leave' | 'stayIn' | 'stayOut';\n\nfunction classifyMembership<\n Col extends string,\n R extends Record<string, unknown>,\n>(where: Expr<Col> | undefined, oldRow: R, newRow: R): MembershipChange {\n // No filter: everything is in, so updates are always \"stayIn\".\n if (!where) {\n return 'stayIn';\n }\n\n const oldIn = evaluate(where, oldRow);\n const newIn = evaluate(where, newRow);\n\n if (oldIn && !newIn) {\n return 'leave';\n }\n if (!oldIn && newIn) {\n return 'enter';\n }\n if (oldIn && newIn) {\n return 'stayIn';\n }\n return 'stayOut';\n}\n\n/**\n * Extracts the column names from a RowType whose values are of type Value.\n * Note that this will exclude columns that are of type object, array, etc.\n */\ntype ColumnsFromRow<R> = {\n [K in keyof R]-?: R[K] extends Value | undefined ? K : never;\n}[keyof R] &\n string;\n\n/**\n * React hook to subscribe to a table in SpacetimeDB and receive live updates as rows are inserted, updated, or deleted.\n *\n * This hook returns a snapshot of the table's rows, filtered by an optional `where` clause, and provides a loading state\n * until the initial subscription is applied. It also allows you to specify callbacks for row insertions, deletions, and updates.\n *\n * The hook must be used within a component tree wrapped by `SpacetimeDBProvider`.\n *\n * Overloads:\n * - `useTable(tableName, where, callbacks?)`: Subscribe to a table with a filter and optional callbacks.\n * - `useTable(tableName, callbacks?)`: Subscribe to a table without a filter, with optional callbacks.\n *\n * @template DbConnection The type of the SpacetimeDB connection.\n * @template RowType The type of the table row.\n * @template TableName The name of the table.\n *\n * @param tableName - The name of the table to subscribe to.\n * @param whereClauseOrCallbacks - (Optional) Either a filter expression (where clause) or the callbacks object.\n * @param callbacks - (Optional) Callbacks for row insert, delete, and update events.\n *\n * @returns A snapshot object containing the current rows and the subscription state (`'loading'` or `'ready'`).\n *\n * @throws Error if the hook is used outside of a `SpacetimeDBProvider`.\n *\n * @example\n * ```tsx\n * const { rows, state } = useTable('users', where(eq('isActive', true)), {\n * onInsert: (row) => console.log('Inserted:', row),\n * onDelete: (row) => console.log('Deleted:', row),\n * onUpdate: (oldRow, newRow) => console.log('Updated:', oldRow, newRow),\n * });\n * ```\n */\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n where: Expr<ColumnsFromRow<RowType>>,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType>;\n\n/**\n * React hook to subscribe to a table in SpacetimeDB and receive live updates as rows are inserted, updated, or deleted.\n *\n * This hook returns a snapshot of the table's rows, filtered by an optional `where` clause, and provides a loading state\n * until the initial subscription is applied. It also allows you to specify callbacks for row insertions, deletions, and updates.\n *\n * The hook must be used within a component tree wrapped by `SpacetimeDBProvider`.\n *\n * Overloads:\n * - `useTable(tableName, where, callbacks?)`: Subscribe to a table with a filter and optional callbacks.\n * - `useTable(tableName, callbacks?)`: Subscribe to a table without a filter, with optional callbacks.\n *\n * @template DbConnection The type of the SpacetimeDB connection.\n * @template RowType The type of the table row.\n * @template TableName The name of the table.\n *\n * @param tableName - The name of the table to subscribe to.\n * @param whereClauseOrCallbacks - (Optional) Either a filter expression (where clause) or the callbacks object.\n * @param callbacks - (Optional) Callbacks for row insert, delete, and update events.\n *\n * @returns A snapshot object containing the current rows and the subscription state (`'loading'` or `'ready'`).\n *\n * @throws Error if the hook is used outside of a `SpacetimeDBProvider`.\n *\n * @example\n * ```tsx\n * const { rows, state } = useTable('users', where(eq('isActive', true)), {\n * onInsert: (row) => console.log('Inserted:', row),\n * onDelete: (row) => console.log('Deleted:', row),\n * onUpdate: (oldRow, newRow) => console.log('Updated:', oldRow, newRow),\n * });\n * ```\n */\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType>;\n\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n whereClauseOrCallbacks?:\n | Expr<ColumnsFromRow<RowType>>\n | UseQueryCallbacks<RowType>,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType> {\n let whereClause: Expr<ColumnsFromRow<RowType>> | undefined;\n if (\n whereClauseOrCallbacks &&\n typeof whereClauseOrCallbacks === 'object' &&\n 'type' in whereClauseOrCallbacks\n ) {\n whereClause = whereClauseOrCallbacks as Expr<ColumnsFromRow<RowType>>;\n } else {\n callbacks = whereClauseOrCallbacks as\n | UseQueryCallbacks<RowType>\n | undefined;\n }\n const [subscribeApplied, setSubscribeApplied] = useState(false);\n const [isActive, setIsActive] = useState(false);\n let spacetime: DbConnection | undefined;\n try {\n spacetime = useSpacetimeDB<DbConnection>();\n } catch {\n throw new Error(\n 'Could not find SpacetimeDB client! Did you forget to add a ' +\n '`SpacetimeDBProvider`? `useTable` must be used in the React component tree ' +\n 'under a `SpacetimeDBProvider` component.'\n );\n }\n const client = spacetime;\n\n const query =\n `SELECT * FROM ${tableName}` +\n (whereClause ? ` WHERE ${toString(whereClause)}` : '');\n\n const latestTransactionEvent = useRef<any>(null);\n const lastSnapshotRef = useRef<Snapshot<RowType> | null>(null);\n\n const whereKey = whereClause ? toString(whereClause) : '';\n\n const computeSnapshot = useCallback((): Snapshot<RowType> => {\n const table = client.db[\n tableName as keyof typeof client.db\n ] as unknown as TableCache<RowType>;\n const result: readonly RowType[] = whereClause\n ? table.iter().filter(row => evaluate(whereClause, row))\n : table.iter();\n return {\n rows: result,\n state: subscribeApplied ? 'ready' : 'loading',\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [client, tableName, whereKey, subscribeApplied]);\n\n useEffect(() => {\n const onConnect = () => {\n setIsActive(client.isActive);\n };\n const onDisconnect = () => {\n setIsActive(client.isActive);\n };\n const onConnectError = () => {\n setIsActive(client.isActive);\n };\n client['on']('connect', onConnect);\n client['on']('disconnect', onDisconnect);\n client['on']('connectError', onConnectError);\n return () => {\n client['off']('connect', onConnect);\n client['off']('disconnect', onDisconnect);\n client['off']('connectError', onConnectError);\n };\n }, [client]);\n\n useEffect(() => {\n if (isActive) {\n const cancel = client\n .subscriptionBuilder()\n .onApplied(() => {\n setSubscribeApplied(true);\n })\n .subscribe(query);\n return () => {\n cancel.unsubscribe();\n };\n }\n }, [query, isActive, client]);\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n const onInsert = (ctx: any, row: RowType) => {\n if (whereClause && !evaluate(whereClause, row)) {\n return;\n }\n if (tableName === 'message') {\n console.log('onInsert for messages table:', row);\n }\n callbacks?.onInsert?.(row);\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const onDelete = (ctx: any, row: RowType) => {\n if (whereClause && !evaluate(whereClause, row)) {\n return;\n }\n if (tableName === 'message') {\n console.log('onDelete for messages table:', row);\n }\n callbacks?.onDelete?.(row);\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const onUpdate = (ctx: any, oldRow: RowType, newRow: RowType) => {\n const change = classifyMembership(whereClause, oldRow, newRow);\n\n switch (change) {\n case 'leave':\n callbacks?.onDelete?.(oldRow);\n break;\n case 'enter':\n callbacks?.onInsert?.(newRow);\n break;\n case 'stayIn':\n callbacks?.onUpdate?.(oldRow, newRow);\n break;\n case 'stayOut':\n return; // no-op\n }\n\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const table = client.db[\n tableName as keyof typeof client.db\n ] as unknown as TableCache<RowType>;\n table.onInsert(onInsert);\n table.onDelete(onDelete);\n table.onUpdate?.(onUpdate);\n\n return () => {\n table.removeOnInsert(onInsert);\n table.removeOnDelete(onDelete);\n table.removeOnUpdate?.(onUpdate);\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n client,\n tableName,\n whereKey,\n callbacks?.onDelete,\n callbacks?.onInsert,\n callbacks?.onUpdate,\n ]\n );\n\n const getSnapshot = useCallback((): Snapshot<RowType> => {\n if (!lastSnapshotRef.current) {\n lastSnapshotRef.current = computeSnapshot();\n }\n return lastSnapshotRef.current;\n }, [computeSnapshot]);\n\n // SSR fallback can be the same getter\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/react/useSpacetimeDB.ts","../../src/react/SpacetimeDBProvider.ts","../../src/react/useTable.ts"],"names":["createContext","useContext","React","where","useState","useRef","useCallback","useEffect","useSyncExternalStore"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAGO,IAAM,kBAAA,GACXA,oBAA4C,MAAS,CAAA;AAIhD,SAAS,cAAA,GAEE;AAChB,EAAA,MAAM,OAAA,GAAUC,iBAAW,kBAAkB,CAAA;AAC7C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;ACEO,SAAS,mBAAA,CAId;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAA,EAIsB;AACpB,EAAA,OAAaC,gBAAA,CAAA,aAAA;AAAA,IACX,kBAAA,CAAmB,QAAA;AAAA,IACnB,EAAE,KAAA,EAAO,iBAAA,CAAkB,KAAA,EAAM,EAAE;AAAA;AAAA,IACnC;AAAA,GACF;AACF;ACdO,IAAM,EAAA,GAAK,CAChB,GAAA,EACA,KAAA,MACkB,EAAE,IAAA,EAAM,IAAA,EAAM,KAAK,KAAA,EAAM;AA4CtC,SAAS,QAAA,CACd,MACA,GAAA,EACS;AACT,EAAA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,CAAA;AAC7B,QAAA,KAAA,CAAM,iBAAiB,QAAQ,CAAA;AAAA,MACjC,CAAA;AAAA,IACF,CAAA;AAAA;AAAA,IAEA;AAAA,MACE,MAAA;AAAA,MACA,SAAA;AAAA,MACA,QAAA;AAAA,MACA,SAAA,EAAW,QAAA;AAAA,MACX,SAAA,EAAW,QAAA;AAAA,MACX,SAAA,EAAW;AAAA;AACb,GACF;AAEA,EAAA,MAAM,WAAA,GAAcA,kBAAY,MAAyB;AACvD,IAAA,IAAI,CAAC,gBAAgB,OAAA,EAAS;AAC5B,MAAA,eAAA,CAAgB,UAAU,eAAA,EAAgB;AAAA,IAC5C;AACA,IAAA,OAAO,eAAA,CAAgB,OAAA;AAAA,EACzB,CAAA,EAAG,CAAC,eAAe,CAAC,CAAA;AAGpB,EAAA,OAAOE,0BAAA,CAAqB,SAAA,EAAW,WAAA,EAAa,WAAW,CAAA;AACjE","file":"index.cjs","sourcesContent":["import { createContext, useContext, type Context } from 'react';\nimport type { DbConnectionImpl } from '../sdk/db_connection_impl';\n\nexport const SpacetimeDBContext: Context<DbConnectionImpl | undefined> =\n createContext<DbConnectionImpl | undefined>(undefined);\n\n// Throws an error if used outside of a SpacetimeDBProvider\n// Error is caught by other hooks like useTable so they can provide better error messages\nexport function useSpacetimeDB<\n DbConnection extends DbConnectionImpl,\n>(): DbConnection {\n const context = useContext(SpacetimeDBContext) as DbConnection | undefined;\n if (!context) {\n throw new Error(\n 'useSpacetimeDB must be used within a SpacetimeDBProvider component. Did you forget to add a `SpacetimeDBProvider` to your component tree?'\n );\n }\n return context;\n}\n","import {\n DbConnectionBuilder,\n type DbConnectionImpl,\n} from '../sdk/db_connection_impl';\nimport * as React from 'react';\nimport { SpacetimeDBContext } from './useSpacetimeDB';\n\nexport interface SpacetimeDBProviderProps<\n DbConnection extends DbConnectionImpl,\n ErrorContext,\n SubscriptionEventContext,\n> {\n connectionBuilder: DbConnectionBuilder<\n DbConnection,\n ErrorContext,\n SubscriptionEventContext\n >;\n children?: React.ReactNode;\n}\n\nexport function SpacetimeDBProvider<\n DbConnection extends DbConnectionImpl,\n ErrorContext,\n SubscriptionEventContext,\n>({\n connectionBuilder,\n children,\n}: SpacetimeDBProviderProps<\n DbConnection,\n ErrorContext,\n SubscriptionEventContext\n>): React.JSX.Element {\n return React.createElement(\n SpacetimeDBContext.Provider,\n { value: connectionBuilder.build() }, // May need to modify this to do it lazily in server-side rendering\n children\n );\n}\n","import {\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { useSpacetimeDB } from './useSpacetimeDB';\nimport { DbConnectionImpl, TableCache } from '../sdk/db_connection_impl';\n\nexport interface UseQueryCallbacks<RowType> {\n onInsert?: (row: RowType) => void;\n onDelete?: (row: RowType) => void;\n onUpdate?: (oldRow: RowType, newRow: RowType) => void;\n}\n\nexport type Value = string | number | boolean;\n\nexport type Expr<Column extends string> =\n | { type: 'eq'; key: Column; value: Value }\n | { type: 'and'; children: Expr<Column>[] }\n | { type: 'or'; children: Expr<Column>[] };\n\nexport const eq = <Column extends string>(\n key: Column,\n value: Value\n): Expr<Column> => ({ type: 'eq', key, value });\n\nexport const and = <Column extends string>(\n ...children: Expr<Column>[]\n): Expr<Column> => {\n const flat: Expr<Column>[] = [];\n for (const c of children) {\n if (!c) continue;\n if (c.type === 'and') flat.push(...c.children);\n else flat.push(c);\n }\n const pruned = flat.filter(Boolean);\n if (pruned.length === 0) return { type: 'and', children: [] };\n if (pruned.length === 1) return pruned[0];\n return { type: 'and', children: pruned };\n};\n\nexport const or = <Column extends string>(\n ...children: Expr<Column>[]\n): Expr<Column> => {\n const flat: Expr<Column>[] = [];\n for (const c of children) {\n if (!c) continue;\n if (c.type === 'or') flat.push(...c.children);\n else flat.push(c);\n }\n const pruned = flat.filter(Boolean);\n if (pruned.length === 0) return { type: 'or', children: [] };\n if (pruned.length === 1) return pruned[0];\n return { type: 'or', children: pruned };\n};\n\nexport const isEq = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'eq' }> => e.type === 'eq';\nexport const isAnd = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'and' }> => e.type === 'and';\nexport const isOr = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'or' }> => e.type === 'or';\n\ntype RecordLike<Column extends string> = Record<Column, unknown>;\n\nexport function evaluate<Column extends string>(\n expr: Expr<Column>,\n row: RecordLike<Column>\n): boolean {\n switch (expr.type) {\n case 'eq': {\n const v = row[expr.key];\n if (\n typeof v === 'string' ||\n typeof v === 'number' ||\n typeof v === 'boolean'\n ) {\n return v === expr.value;\n }\n return false;\n }\n case 'and':\n return (\n expr.children.length === 0 || expr.children.every(c => evaluate(c, row))\n );\n case 'or':\n return (\n expr.children.length !== 0 && expr.children.some(c => evaluate(c, row))\n );\n }\n}\n\nfunction formatValue(v: Value): string {\n switch (typeof v) {\n case 'string':\n return `'${v.replace(/'/g, \"''\")}'`;\n case 'number':\n return Number.isFinite(v) ? String(v) : `'${String(v)}'`;\n case 'boolean':\n return v ? 'TRUE' : 'FALSE';\n }\n}\n\nfunction escapeIdent(id: string): string {\n if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(id)) return id;\n return `\"${id.replace(/\"/g, '\"\"')}\"`;\n}\n\nfunction parenthesize(s: string): string {\n if (!s.includes(' AND ') && !s.includes(' OR ')) return s;\n return `(${s})`;\n}\n\nexport function toString<Column extends string>(expr: Expr<Column>): string {\n switch (expr.type) {\n case 'eq':\n return `${escapeIdent(expr.key)} = ${formatValue(expr.value)}`;\n case 'and':\n return parenthesize(expr.children.map(toString).join(' AND '));\n case 'or':\n return parenthesize(expr.children.map(toString).join(' OR '));\n }\n}\n\n/**\n * This is just the identity function to make things look like SQL.\n * @param expr\n * @returns\n */\nexport function where<Column extends string>(expr: Expr<Column>): Expr<Column> {\n return expr;\n}\n\ntype Snapshot<RowType> = {\n readonly rows: readonly RowType[];\n readonly state: 'loading' | 'ready';\n};\n\ntype MembershipChange = 'enter' | 'leave' | 'stayIn' | 'stayOut';\n\nfunction classifyMembership<\n Col extends string,\n R extends Record<string, unknown>,\n>(where: Expr<Col> | undefined, oldRow: R, newRow: R): MembershipChange {\n // No filter: everything is in, so updates are always \"stayIn\".\n if (!where) {\n return 'stayIn';\n }\n\n const oldIn = evaluate(where, oldRow);\n const newIn = evaluate(where, newRow);\n\n if (oldIn && !newIn) {\n return 'leave';\n }\n if (!oldIn && newIn) {\n return 'enter';\n }\n if (oldIn && newIn) {\n return 'stayIn';\n }\n return 'stayOut';\n}\n\n/**\n * Extracts the column names from a RowType whose values are of type Value.\n * Note that this will exclude columns that are of type object, array, etc.\n */\ntype ColumnsFromRow<R> = {\n [K in keyof R]-?: R[K] extends Value | undefined ? K : never;\n}[keyof R] &\n string;\n\n/**\n * React hook to subscribe to a table in SpacetimeDB and receive live updates as rows are inserted, updated, or deleted.\n *\n * This hook returns a snapshot of the table's rows, filtered by an optional `where` clause, and provides a loading state\n * until the initial subscription is applied. It also allows you to specify callbacks for row insertions, deletions, and updates.\n *\n * The hook must be used within a component tree wrapped by `SpacetimeDBProvider`.\n *\n * Overloads:\n * - `useTable(tableName, where, callbacks?)`: Subscribe to a table with a filter and optional callbacks.\n * - `useTable(tableName, callbacks?)`: Subscribe to a table without a filter, with optional callbacks.\n *\n * @template DbConnection The type of the SpacetimeDB connection.\n * @template RowType The type of the table row.\n * @template TableName The name of the table.\n *\n * @param tableName - The name of the table to subscribe to.\n * @param whereClauseOrCallbacks - (Optional) Either a filter expression (where clause) or the callbacks object.\n * @param callbacks - (Optional) Callbacks for row insert, delete, and update events.\n *\n * @returns A snapshot object containing the current rows and the subscription state (`'loading'` or `'ready'`).\n *\n * @throws Error if the hook is used outside of a `SpacetimeDBProvider`.\n *\n * @example\n * ```tsx\n * const { rows, state } = useTable('users', where(eq('isActive', true)), {\n * onInsert: (row) => console.log('Inserted:', row),\n * onDelete: (row) => console.log('Deleted:', row),\n * onUpdate: (oldRow, newRow) => console.log('Updated:', oldRow, newRow),\n * });\n * ```\n */\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n where: Expr<ColumnsFromRow<RowType>>,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType>;\n\n/**\n * React hook to subscribe to a table in SpacetimeDB and receive live updates as rows are inserted, updated, or deleted.\n *\n * This hook returns a snapshot of the table's rows, filtered by an optional `where` clause, and provides a loading state\n * until the initial subscription is applied. It also allows you to specify callbacks for row insertions, deletions, and updates.\n *\n * The hook must be used within a component tree wrapped by `SpacetimeDBProvider`.\n *\n * Overloads:\n * - `useTable(tableName, where, callbacks?)`: Subscribe to a table with a filter and optional callbacks.\n * - `useTable(tableName, callbacks?)`: Subscribe to a table without a filter, with optional callbacks.\n *\n * @template DbConnection The type of the SpacetimeDB connection.\n * @template RowType The type of the table row.\n * @template TableName The name of the table.\n *\n * @param tableName - The name of the table to subscribe to.\n * @param whereClauseOrCallbacks - (Optional) Either a filter expression (where clause) or the callbacks object.\n * @param callbacks - (Optional) Callbacks for row insert, delete, and update events.\n *\n * @returns A snapshot object containing the current rows and the subscription state (`'loading'` or `'ready'`).\n *\n * @throws Error if the hook is used outside of a `SpacetimeDBProvider`.\n *\n * @example\n * ```tsx\n * const { rows, state } = useTable('users', where(eq('isActive', true)), {\n * onInsert: (row) => console.log('Inserted:', row),\n * onDelete: (row) => console.log('Deleted:', row),\n * onUpdate: (oldRow, newRow) => console.log('Updated:', oldRow, newRow),\n * });\n * ```\n */\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType>;\n\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n whereClauseOrCallbacks?:\n | Expr<ColumnsFromRow<RowType>>\n | UseQueryCallbacks<RowType>,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType> {\n let whereClause: Expr<ColumnsFromRow<RowType>> | undefined;\n if (\n whereClauseOrCallbacks &&\n typeof whereClauseOrCallbacks === 'object' &&\n 'type' in whereClauseOrCallbacks\n ) {\n whereClause = whereClauseOrCallbacks as Expr<ColumnsFromRow<RowType>>;\n } else {\n callbacks = whereClauseOrCallbacks as\n | UseQueryCallbacks<RowType>\n | undefined;\n }\n const [subscribeApplied, setSubscribeApplied] = useState(false);\n const [isActive, setIsActive] = useState(false);\n let spacetime: DbConnection | undefined;\n try {\n spacetime = useSpacetimeDB<DbConnection>();\n } catch {\n throw new Error(\n 'Could not find SpacetimeDB client! Did you forget to add a ' +\n '`SpacetimeDBProvider`? `useTable` must be used in the React component tree ' +\n 'under a `SpacetimeDBProvider` component.'\n );\n }\n const client = spacetime;\n\n const query =\n `SELECT * FROM ${tableName}` +\n (whereClause ? ` WHERE ${toString(whereClause)}` : '');\n\n const latestTransactionEvent = useRef<any>(null);\n const lastSnapshotRef = useRef<Snapshot<RowType> | null>(null);\n\n const whereKey = whereClause ? toString(whereClause) : '';\n\n const computeSnapshot = useCallback((): Snapshot<RowType> => {\n const table = client.db[\n tableName as keyof typeof client.db\n ] as unknown as TableCache<RowType>;\n const result: readonly RowType[] = whereClause\n ? table.iter().filter(row => evaluate(whereClause, row))\n : table.iter();\n return {\n rows: result,\n state: subscribeApplied ? 'ready' : 'loading',\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [client, tableName, whereKey, subscribeApplied]);\n\n useEffect(() => {\n const onConnect = () => {\n setIsActive(client.isActive);\n };\n const onDisconnect = () => {\n setIsActive(client.isActive);\n };\n const onConnectError = () => {\n setIsActive(client.isActive);\n };\n client['on']('connect', onConnect);\n client['on']('disconnect', onDisconnect);\n client['on']('connectError', onConnectError);\n return () => {\n client['off']('connect', onConnect);\n client['off']('disconnect', onDisconnect);\n client['off']('connectError', onConnectError);\n };\n }, [client]);\n\n useEffect(() => {\n if (isActive) {\n const cancel = client\n .subscriptionBuilder()\n .onApplied(() => {\n setSubscribeApplied(true);\n })\n .subscribe(query);\n return () => {\n cancel.unsubscribe();\n };\n }\n }, [query, isActive, client]);\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n const onInsert = (ctx: any, row: RowType) => {\n if (whereClause && !evaluate(whereClause, row)) {\n return;\n }\n if (tableName === 'message') {\n console.log('onInsert for messages table:', row);\n }\n callbacks?.onInsert?.(row);\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const onDelete = (ctx: any, row: RowType) => {\n if (whereClause && !evaluate(whereClause, row)) {\n return;\n }\n if (tableName === 'message') {\n console.log('onDelete for messages table:', row);\n }\n callbacks?.onDelete?.(row);\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const onUpdate = (ctx: any, oldRow: RowType, newRow: RowType) => {\n const change = classifyMembership(whereClause, oldRow, newRow);\n\n switch (change) {\n case 'leave':\n callbacks?.onDelete?.(oldRow);\n break;\n case 'enter':\n callbacks?.onInsert?.(newRow);\n break;\n case 'stayIn':\n callbacks?.onUpdate?.(oldRow, newRow);\n break;\n case 'stayOut':\n return; // no-op\n }\n\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const table = client.db[\n tableName as keyof typeof client.db\n ] as unknown as TableCache<RowType>;\n table.onInsert(onInsert);\n table.onDelete(onDelete);\n table.onUpdate?.(onUpdate);\n\n return () => {\n table.removeOnInsert(onInsert);\n table.removeOnDelete(onDelete);\n table.removeOnUpdate?.(onUpdate);\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n client,\n tableName,\n whereKey,\n callbacks?.onDelete,\n callbacks?.onInsert,\n callbacks?.onUpdate,\n ]\n );\n\n const getSnapshot = useCallback((): Snapshot<RowType> => {\n if (!lastSnapshotRef.current) {\n lastSnapshotRef.current = computeSnapshot();\n }\n return lastSnapshotRef.current;\n }, [computeSnapshot]);\n\n // SSR fallback can be the same getter\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/react/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/useSpacetimeDB.ts","../../src/react/SpacetimeDBProvider.ts","../../src/react/useTable.ts"],"names":["where"],"mappings":";;;;AAGO,IAAM,kBAAA,GACX,cAA4C,MAAS,CAAA;AAIhD,SAAS,cAAA,GAEE;AAChB,EAAA,MAAM,OAAA,GAAU,WAAW,kBAAkB,CAAA;AAC7C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;ACDO,SAAS,mBAAA,CAId;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAA,EAIsB;AACpB,EAAA,OAAa,KAAA,CAAA,aAAA;AAAA,IACX,kBAAA,CAAmB,QAAA;AAAA,IACnB,EAAE,KAAA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M,SAAS,QAAQ,CAAA;AACvB,MAAA,KAAA,CAAM,SAAS,QAAQ,CAAA;AACvB,MAAA,KAAA,CAAM,WAAW,QAAQ,CAAA;AAEzB,MAAA,OAAO,MAAM;AACX,QAAA,KAAA,CAAM,eAAe,QAAQ,CAAA;AAC7B,QAAA,KAAA,CAAM,eAAe,QAAQ,CAAA;AAC7B,QAAA,KAAA,CAAM,iBAAiB,QAAQ,CAAA;AAAA,MACjC,CAAA;AAAA,IACF,CAAA;AAAA;AAAA,IAEA;AAAA,MACE,MAAA;AAAA,MACA,SAAA;AAAA,MACA,QAAA;AAAA,MACA,SAAA,EAAW,QAAA;AAAA,MACX,SAAA,EAAW,QAAA;AAAA,MACX,SAAA,EAAW;AAAA;AACb,GACF;AAEA,EAAA,MAAM,WAAA,GAAc,YAAY,MAAyB;AACvD,IAAA,IAAI,CAAC,gBAAgB,OAAA,EAAS;AAC5B,MAAA,eAAA,CAAgB,UAAU,eAAA,EAAgB;AAAA,IAC5C;AACA,IAAA,OAAO,eAAA,CAAgB,OAAA;AAAA,EACzB,CAAA,EAAG,CAAC,eAAe,CAAC,CAAA;AAGpB,EAAA,OAAO,oBAAA,CAAqB,SAAA,EAAW,WAAA,EAAa,WAAW,CAAA;AACjE","file":"index.mjs","sourcesContent":["import { createContext, useContext, type Context } from 'react';\nimport type { DbConnectionImpl } from '../index';\n\nexport const SpacetimeDBContext: Context<DbConnectionImpl | undefined> =\n createContext<DbConnectionImpl | undefined>(undefined);\n\n// Throws an error if used outside of a SpacetimeDBProvider\n// Error is caught by other hooks like useTable so they can provide better error messages\nexport function useSpacetimeDB<\n DbConnection extends DbConnectionImpl,\n>(): DbConnection {\n const context = useContext(SpacetimeDBContext) as DbConnection | undefined;\n if (!context) {\n throw new Error(\n 'useSpacetimeDB must be used within a SpacetimeDBProvider component. Did you forget to add a `SpacetimeDBProvider` to your component tree?'\n );\n }\n return context;\n}\n","import { DbConnectionBuilder, type DbConnectionImpl } from '../index';\nimport * as React from 'react';\nimport { SpacetimeDBContext } from './useSpacetimeDB';\n\nexport interface SpacetimeDBProviderProps<\n DbConnection extends DbConnectionImpl,\n ErrorContext,\n SubscriptionEventContext,\n> {\n connectionBuilder: DbConnectionBuilder<\n DbConnection,\n ErrorContext,\n SubscriptionEventContext\n >;\n children?: React.ReactNode;\n}\n\nexport function SpacetimeDBProvider<\n DbConnection extends DbConnectionImpl,\n ErrorContext,\n SubscriptionEventContext,\n>({\n connectionBuilder,\n children,\n}: SpacetimeDBProviderProps<\n DbConnection,\n ErrorContext,\n SubscriptionEventContext\n>): React.JSX.Element {\n return React.createElement(\n SpacetimeDBContext.Provider,\n { value: connectionBuilder.build() }, // May need to modify this to do it lazily in server-side rendering\n children\n );\n}\n","import {\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { useSpacetimeDB } from './useSpacetimeDB';\nimport { DbConnectionImpl, TableCache } from '../sdk';\n\nexport interface UseQueryCallbacks<RowType> {\n onInsert?: (row: RowType) => void;\n onDelete?: (row: RowType) => void;\n onUpdate?: (oldRow: RowType, newRow: RowType) => void;\n}\n\nexport type Value = string | number | boolean;\n\nexport type Expr<Column extends string> =\n | { type: 'eq'; key: Column; value: Value }\n | { type: 'and'; children: Expr<Column>[] }\n | { type: 'or'; children: Expr<Column>[] };\n\nexport const eq = <Column extends string>(\n key: Column,\n value: Value\n): Expr<Column> => ({ type: 'eq', key, value });\n\nexport const and = <Column extends string>(\n ...children: Expr<Column>[]\n): Expr<Column> => {\n const flat: Expr<Column>[] = [];\n for (const c of children) {\n if (!c) continue;\n if (c.type === 'and') flat.push(...c.children);\n else flat.push(c);\n }\n const pruned = flat.filter(Boolean);\n if (pruned.length === 0) return { type: 'and', children: [] };\n if (pruned.length === 1) return pruned[0];\n return { type: 'and', children: pruned };\n};\n\nexport const or = <Column extends string>(\n ...children: Expr<Column>[]\n): Expr<Column> => {\n const flat: Expr<Column>[] = [];\n for (const c of children) {\n if (!c) continue;\n if (c.type === 'or') flat.push(...c.children);\n else flat.push(c);\n }\n const pruned = flat.filter(Boolean);\n if (pruned.length === 0) return { type: 'or', children: [] };\n if (pruned.length === 1) return pruned[0];\n return { type: 'or', children: pruned };\n};\n\nexport const isEq = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'eq' }> => e.type === 'eq';\nexport const isAnd = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'and' }> => e.type === 'and';\nexport const isOr = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'or' }> => e.type === 'or';\n\ntype RecordLike<Column extends string> = Record<Column, unknown>;\n\nexport function evaluate<Column extends string>(\n expr: Expr<Column>,\n row: RecordLike<Column>\n): boolean {\n switch (expr.type) {\n case 'eq': {\n const v = row[expr.key];\n if (\n typeof v === 'string' ||\n typeof v === 'number' ||\n typeof v === 'boolean'\n ) {\n return v === expr.value;\n }\n return false;\n }\n case 'and':\n return (\n expr.children.length === 0 || expr.children.every(c => evaluate(c, row))\n );\n case 'or':\n return (\n expr.children.length !== 0 && expr.children.some(c => evaluate(c, row))\n );\n }\n}\n\nfunction formatValue(v: Value): string {\n switch (typeof v) {\n case 'string':\n return `'${v.replace(/'/g, \"''\")}'`;\n case 'number':\n return Number.isFinite(v) ? String(v) : `'${String(v)}'`;\n case 'boolean':\n return v ? 'TRUE' : 'FALSE';\n }\n}\n\nfunction escapeIdent(id: string): string {\n if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(id)) return id;\n return `\"${id.replace(/\"/g, '\"\"')}\"`;\n}\n\nfunction parenthesize(s: string): string {\n if (!s.includes(' AND ') && !s.includes(' OR ')) return s;\n return `(${s})`;\n}\n\nexport function toString<Column extends string>(expr: Expr<Column>): string {\n switch (expr.type) {\n case 'eq':\n return `${escapeIdent(expr.key)} = ${formatValue(expr.value)}`;\n case 'and':\n return parenthesize(expr.children.map(toString).join(' AND '));\n case 'or':\n return parenthesize(expr.children.map(toString).join(' OR '));\n }\n}\n\n/**\n * This is just the identity function to make things look like SQL.\n * @param expr\n * @returns\n */\nexport function where<Column extends string>(expr: Expr<Column>): Expr<Column> {\n return expr;\n}\n\ntype Snapshot<RowType> = {\n readonly rows: readonly RowType[];\n readonly state: 'loading' | 'ready';\n};\n\ntype MembershipChange = 'enter' | 'leave' | 'stayIn' | 'stayOut';\n\nfunction classifyMembership<\n Col extends string,\n R extends Record<string, unknown>,\n>(where: Expr<Col> | undefined, oldRow: R, newRow: R): MembershipChange {\n // No filter: everything is in, so updates are always \"stayIn\".\n if (!where) {\n return 'stayIn';\n }\n\n const oldIn = evaluate(where, oldRow);\n const newIn = evaluate(where, newRow);\n\n if (oldIn && !newIn) {\n return 'leave';\n }\n if (!oldIn && newIn) {\n return 'enter';\n }\n if (oldIn && newIn) {\n return 'stayIn';\n }\n return 'stayOut';\n}\n\n/**\n * Extracts the column names from a RowType whose values are of type Value.\n * Note that this will exclude columns that are of type object, array, etc.\n */\ntype ColumnsFromRow<R> = {\n [K in keyof R]-?: R[K] extends Value | undefined ? K : never;\n}[keyof R] &\n string;\n\n/**\n * React hook to subscribe to a table in SpacetimeDB and receive live updates as rows are inserted, updated, or deleted.\n *\n * This hook returns a snapshot of the table's rows, filtered by an optional `where` clause, and provides a loading state\n * until the initial subscription is applied. It also allows you to specify callbacks for row insertions, deletions, and updates.\n *\n * The hook must be used within a component tree wrapped by `SpacetimeDBProvider`.\n *\n * Overloads:\n * - `useTable(tableName, where, callbacks?)`: Subscribe to a table with a filter and optional callbacks.\n * - `useTable(tableName, callbacks?)`: Subscribe to a table without a filter, with optional callbacks.\n *\n * @template DbConnection The type of the SpacetimeDB connection.\n * @template RowType The type of the table row.\n * @template TableName The name of the table.\n *\n * @param tableName - The name of the table to subscribe to.\n * @param whereClauseOrCallbacks - (Optional) Either a filter expression (where clause) or the callbacks object.\n * @param callbacks - (Optional) Callbacks for row insert, delete, and update events.\n *\n * @returns A snapshot object containing the current rows and the subscription state (`'loading'` or `'ready'`).\n *\n * @throws Error if the hook is used outside of a `SpacetimeDBProvider`.\n *\n * @example\n * ```tsx\n * const { rows, state } = useTable('users', where(eq('isActive', true)), {\n * onInsert: (row) => console.log('Inserted:', row),\n * onDelete: (row) => console.log('Deleted:', row),\n * onUpdate: (oldRow, newRow) => console.log('Updated:', oldRow, newRow),\n * });\n * ```\n */\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n where: Expr<ColumnsFromRow<RowType>>,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType>;\n\n/**\n * React hook to subscribe to a table in SpacetimeDB and receive live updates as rows are inserted, updated, or deleted.\n *\n * This hook returns a snapshot of the table's rows, filtered by an optional `where` clause, and provides a loading state\n * until the initial subscription is applied. It also allows you to specify callbacks for row insertions, deletions, and updates.\n *\n * The hook must be used within a component tree wrapped by `SpacetimeDBProvider`.\n *\n * Overloads:\n * - `useTable(tableName, where, callbacks?)`: Subscribe to a table with a filter and optional callbacks.\n * - `useTable(tableName, callbacks?)`: Subscribe to a table without a filter, with optional callbacks.\n *\n * @template DbConnection The type of the SpacetimeDB connection.\n * @template RowType The type of the table row.\n * @template TableName The name of the table.\n *\n * @param tableName - The name of the table to subscribe to.\n * @param whereClauseOrCallbacks - (Optional) Either a filter expression (where clause) or the callbacks object.\n * @param callbacks - (Optional) Callbacks for row insert, delete, and update events.\n *\n * @returns A snapshot object containing the current rows and the subscription state (`'loading'` or `'ready'`).\n *\n * @throws Error if the hook is used outside of a `SpacetimeDBProvider`.\n *\n * @example\n * ```tsx\n * const { rows, state } = useTable('users', where(eq('isActive', true)), {\n * onInsert: (row) => console.log('Inserted:', row),\n * onDelete: (row) => console.log('Deleted:', row),\n * onUpdate: (oldRow, newRow) => console.log('Updated:', oldRow, newRow),\n * });\n * ```\n */\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType>;\n\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n whereClauseOrCallbacks?:\n | Expr<ColumnsFromRow<RowType>>\n | UseQueryCallbacks<RowType>,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType> {\n let whereClause: Expr<ColumnsFromRow<RowType>> | undefined;\n if (\n whereClauseOrCallbacks &&\n typeof whereClauseOrCallbacks === 'object' &&\n 'type' in whereClauseOrCallbacks\n ) {\n whereClause = whereClauseOrCallbacks as Expr<ColumnsFromRow<RowType>>;\n } else {\n callbacks = whereClauseOrCallbacks as\n | UseQueryCallbacks<RowType>\n | undefined;\n }\n const [subscribeApplied, setSubscribeApplied] = useState(false);\n const [isActive, setIsActive] = useState(false);\n let spacetime: DbConnection | undefined;\n try {\n spacetime = useSpacetimeDB<DbConnection>();\n } catch {\n throw new Error(\n 'Could not find SpacetimeDB client! Did you forget to add a ' +\n '`SpacetimeDBProvider`? `useTable` must be used in the React component tree ' +\n 'under a `SpacetimeDBProvider` component.'\n );\n }\n const client = spacetime;\n\n const query =\n `SELECT * FROM ${tableName}` +\n (whereClause ? ` WHERE ${toString(whereClause)}` : '');\n\n const latestTransactionEvent = useRef<any>(null);\n const lastSnapshotRef = useRef<Snapshot<RowType> | null>(null);\n\n const whereKey = whereClause ? toString(whereClause) : '';\n\n const computeSnapshot = useCallback((): Snapshot<RowType> => {\n const table = client.db[\n tableName as keyof typeof client.db\n ] as unknown as TableCache<RowType>;\n const result: readonly RowType[] = whereClause\n ? table.iter().filter(row => evaluate(whereClause, row))\n : table.iter();\n return {\n rows: result,\n state: subscribeApplied ? 'ready' : 'loading',\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [client, tableName, whereKey, subscribeApplied]);\n\n useEffect(() => {\n const onConnect = () => {\n setIsActive(client.isActive);\n };\n const onDisconnect = () => {\n setIsActive(client.isActive);\n };\n const onConnectError = () => {\n setIsActive(client.isActive);\n };\n client['on']('connect', onConnect);\n client['on']('disconnect', onDisconnect);\n client['on']('connectError', onConnectError);\n return () => {\n client['off']('connect', onConnect);\n client['off']('disconnect', onDisconnect);\n client['off']('connectError', onConnectError);\n };\n }, [client]);\n\n useEffect(() => {\n if (isActive) {\n const cancel = client\n .subscriptionBuilder()\n .onApplied(() => {\n setSubscribeApplied(true);\n })\n .subscribe(query);\n return () => {\n cancel.unsubscribe();\n };\n }\n }, [query, isActive, client]);\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n const onInsert = (ctx: any, row: RowType) => {\n if (whereClause && !evaluate(whereClause, row)) {\n return;\n }\n if (tableName === 'message') {\n console.log('onInsert for messages table:', row);\n }\n callbacks?.onInsert?.(row);\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const onDelete = (ctx: any, row: RowType) => {\n if (whereClause && !evaluate(whereClause, row)) {\n return;\n }\n if (tableName === 'message') {\n console.log('onDelete for messages table:', row);\n }\n callbacks?.onDelete?.(row);\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const onUpdate = (ctx: any, oldRow: RowType, newRow: RowType) => {\n const change = classifyMembership(whereClause, oldRow, newRow);\n\n switch (change) {\n case 'leave':\n callbacks?.onDelete?.(oldRow);\n break;\n case 'enter':\n callbacks?.onInsert?.(newRow);\n break;\n case 'stayIn':\n callbacks?.onUpdate?.(oldRow, newRow);\n break;\n case 'stayOut':\n return; // no-op\n }\n\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const table = client.db[\n tableName as keyof typeof client.db\n ] as unknown as TableCache<RowType>;\n table.onInsert(onInsert);\n table.onDelete(onDelete);\n table.onUpdate?.(onUpdate);\n\n return () => {\n table.removeOnInsert(onInsert);\n table.removeOnDelete(onDelete);\n table.removeOnUpdate?.(onUpdate);\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n client,\n tableName,\n whereKey,\n callbacks?.onDelete,\n callbacks?.onInsert,\n callbacks?.onUpdate,\n ]\n );\n\n const getSnapshot = useCallback((): Snapshot<RowType> => {\n if (!lastSnapshotRef.current) {\n lastSnapshotRef.current = computeSnapshot();\n }\n return lastSnapshotRef.current;\n }, [computeSnapshot]);\n\n // SSR fallback can be the same getter\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/react/useSpacetimeDB.ts","../../src/react/SpacetimeDBProvider.ts","../../src/react/useTable.ts"],"names":["where"],"mappings":";;;;AAGO,IAAM,kBAAA,GACX,cAA4C,MAAS,CAAA;AAIhD,SAAS,cAAA,GAEE;AAChB,EAAA,MAAM,OAAA,GAAU,WAAW,kBAAkB,CAAA;AAC7C,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,OAAA;AACT;;;ACEO,SAAS,mBAAA,CAId;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAA,EAIsB;AACpB,EAAA,OAAa,KAAA,CAAA,aAAA;AAAA,IACX,kBAAA,CAAmB,QAAA;AAAA,IACnB,EAAE,KAAA,EAAO,iBAAA,CAAkB,KAAA,EAAM,EAAE;AAAA;AAAA,IACnC;AAAA,GACF;AACF;ACdO,IAAM,EAAA,GAAK,CAChB,GAAA,EACA,KAAA,MACkB,EAAE,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;AACX,QAAA,KAAA,CAAM,eAAe,QAAQ,CAAA;AAC7B,QAAA,KAAA,CAAM,eAAe,QAAQ,CAAA;AAC7B,QAAA,KAAA,CAAM,iBAAiB,QAAQ,CAAA;AAAA,MACjC,CAAA;AAAA,IACF,CAAA;AAAA;AAAA,IAEA;AAAA,MACE,MAAA;AAAA,MACA,SAAA;AAAA,MACA,QAAA;AAAA,MACA,SAAA,EAAW,QAAA;AAAA,MACX,SAAA,EAAW,QAAA;AAAA,MACX,SAAA,EAAW;AAAA;AACb,GACF;AAEA,EAAA,MAAM,WAAA,GAAc,YAAY,MAAyB;AACvD,IAAA,IAAI,CAAC,gBAAgB,OAAA,EAAS;AAC5B,MAAA,eAAA,CAAgB,UAAU,eAAA,EAAgB;AAAA,IAC5C;AACA,IAAA,OAAO,eAAA,CAAgB,OAAA;AAAA,EACzB,CAAA,EAAG,CAAC,eAAe,CAAC,CAAA;AAGpB,EAAA,OAAO,oBAAA,CAAqB,SAAA,EAAW,WAAA,EAAa,WAAW,CAAA;AACjE","file":"index.mjs","sourcesContent":["import { createContext, useContext, type Context } from 'react';\nimport type { DbConnectionImpl } from '../sdk/db_connection_impl';\n\nexport const SpacetimeDBContext: Context<DbConnectionImpl | undefined> =\n createContext<DbConnectionImpl | undefined>(undefined);\n\n// Throws an error if used outside of a SpacetimeDBProvider\n// Error is caught by other hooks like useTable so they can provide better error messages\nexport function useSpacetimeDB<\n DbConnection extends DbConnectionImpl,\n>(): DbConnection {\n const context = useContext(SpacetimeDBContext) as DbConnection | undefined;\n if (!context) {\n throw new Error(\n 'useSpacetimeDB must be used within a SpacetimeDBProvider component. Did you forget to add a `SpacetimeDBProvider` to your component tree?'\n );\n }\n return context;\n}\n","import {\n DbConnectionBuilder,\n type DbConnectionImpl,\n} from '../sdk/db_connection_impl';\nimport * as React from 'react';\nimport { SpacetimeDBContext } from './useSpacetimeDB';\n\nexport interface SpacetimeDBProviderProps<\n DbConnection extends DbConnectionImpl,\n ErrorContext,\n SubscriptionEventContext,\n> {\n connectionBuilder: DbConnectionBuilder<\n DbConnection,\n ErrorContext,\n SubscriptionEventContext\n >;\n children?: React.ReactNode;\n}\n\nexport function SpacetimeDBProvider<\n DbConnection extends DbConnectionImpl,\n ErrorContext,\n SubscriptionEventContext,\n>({\n connectionBuilder,\n children,\n}: SpacetimeDBProviderProps<\n DbConnection,\n ErrorContext,\n SubscriptionEventContext\n>): React.JSX.Element {\n return React.createElement(\n SpacetimeDBContext.Provider,\n { value: connectionBuilder.build() }, // May need to modify this to do it lazily in server-side rendering\n children\n );\n}\n","import {\n useCallback,\n useEffect,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { useSpacetimeDB } from './useSpacetimeDB';\nimport { DbConnectionImpl, TableCache } from '../sdk/db_connection_impl';\n\nexport interface UseQueryCallbacks<RowType> {\n onInsert?: (row: RowType) => void;\n onDelete?: (row: RowType) => void;\n onUpdate?: (oldRow: RowType, newRow: RowType) => void;\n}\n\nexport type Value = string | number | boolean;\n\nexport type Expr<Column extends string> =\n | { type: 'eq'; key: Column; value: Value }\n | { type: 'and'; children: Expr<Column>[] }\n | { type: 'or'; children: Expr<Column>[] };\n\nexport const eq = <Column extends string>(\n key: Column,\n value: Value\n): Expr<Column> => ({ type: 'eq', key, value });\n\nexport const and = <Column extends string>(\n ...children: Expr<Column>[]\n): Expr<Column> => {\n const flat: Expr<Column>[] = [];\n for (const c of children) {\n if (!c) continue;\n if (c.type === 'and') flat.push(...c.children);\n else flat.push(c);\n }\n const pruned = flat.filter(Boolean);\n if (pruned.length === 0) return { type: 'and', children: [] };\n if (pruned.length === 1) return pruned[0];\n return { type: 'and', children: pruned };\n};\n\nexport const or = <Column extends string>(\n ...children: Expr<Column>[]\n): Expr<Column> => {\n const flat: Expr<Column>[] = [];\n for (const c of children) {\n if (!c) continue;\n if (c.type === 'or') flat.push(...c.children);\n else flat.push(c);\n }\n const pruned = flat.filter(Boolean);\n if (pruned.length === 0) return { type: 'or', children: [] };\n if (pruned.length === 1) return pruned[0];\n return { type: 'or', children: pruned };\n};\n\nexport const isEq = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'eq' }> => e.type === 'eq';\nexport const isAnd = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'and' }> => e.type === 'and';\nexport const isOr = <Column extends string>(\n e: Expr<Column>\n): e is Extract<Expr<Column>, { type: 'or' }> => e.type === 'or';\n\ntype RecordLike<Column extends string> = Record<Column, unknown>;\n\nexport function evaluate<Column extends string>(\n expr: Expr<Column>,\n row: RecordLike<Column>\n): boolean {\n switch (expr.type) {\n case 'eq': {\n const v = row[expr.key];\n if (\n typeof v === 'string' ||\n typeof v === 'number' ||\n typeof v === 'boolean'\n ) {\n return v === expr.value;\n }\n return false;\n }\n case 'and':\n return (\n expr.children.length === 0 || expr.children.every(c => evaluate(c, row))\n );\n case 'or':\n return (\n expr.children.length !== 0 && expr.children.some(c => evaluate(c, row))\n );\n }\n}\n\nfunction formatValue(v: Value): string {\n switch (typeof v) {\n case 'string':\n return `'${v.replace(/'/g, \"''\")}'`;\n case 'number':\n return Number.isFinite(v) ? String(v) : `'${String(v)}'`;\n case 'boolean':\n return v ? 'TRUE' : 'FALSE';\n }\n}\n\nfunction escapeIdent(id: string): string {\n if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(id)) return id;\n return `\"${id.replace(/\"/g, '\"\"')}\"`;\n}\n\nfunction parenthesize(s: string): string {\n if (!s.includes(' AND ') && !s.includes(' OR ')) return s;\n return `(${s})`;\n}\n\nexport function toString<Column extends string>(expr: Expr<Column>): string {\n switch (expr.type) {\n case 'eq':\n return `${escapeIdent(expr.key)} = ${formatValue(expr.value)}`;\n case 'and':\n return parenthesize(expr.children.map(toString).join(' AND '));\n case 'or':\n return parenthesize(expr.children.map(toString).join(' OR '));\n }\n}\n\n/**\n * This is just the identity function to make things look like SQL.\n * @param expr\n * @returns\n */\nexport function where<Column extends string>(expr: Expr<Column>): Expr<Column> {\n return expr;\n}\n\ntype Snapshot<RowType> = {\n readonly rows: readonly RowType[];\n readonly state: 'loading' | 'ready';\n};\n\ntype MembershipChange = 'enter' | 'leave' | 'stayIn' | 'stayOut';\n\nfunction classifyMembership<\n Col extends string,\n R extends Record<string, unknown>,\n>(where: Expr<Col> | undefined, oldRow: R, newRow: R): MembershipChange {\n // No filter: everything is in, so updates are always \"stayIn\".\n if (!where) {\n return 'stayIn';\n }\n\n const oldIn = evaluate(where, oldRow);\n const newIn = evaluate(where, newRow);\n\n if (oldIn && !newIn) {\n return 'leave';\n }\n if (!oldIn && newIn) {\n return 'enter';\n }\n if (oldIn && newIn) {\n return 'stayIn';\n }\n return 'stayOut';\n}\n\n/**\n * Extracts the column names from a RowType whose values are of type Value.\n * Note that this will exclude columns that are of type object, array, etc.\n */\ntype ColumnsFromRow<R> = {\n [K in keyof R]-?: R[K] extends Value | undefined ? K : never;\n}[keyof R] &\n string;\n\n/**\n * React hook to subscribe to a table in SpacetimeDB and receive live updates as rows are inserted, updated, or deleted.\n *\n * This hook returns a snapshot of the table's rows, filtered by an optional `where` clause, and provides a loading state\n * until the initial subscription is applied. It also allows you to specify callbacks for row insertions, deletions, and updates.\n *\n * The hook must be used within a component tree wrapped by `SpacetimeDBProvider`.\n *\n * Overloads:\n * - `useTable(tableName, where, callbacks?)`: Subscribe to a table with a filter and optional callbacks.\n * - `useTable(tableName, callbacks?)`: Subscribe to a table without a filter, with optional callbacks.\n *\n * @template DbConnection The type of the SpacetimeDB connection.\n * @template RowType The type of the table row.\n * @template TableName The name of the table.\n *\n * @param tableName - The name of the table to subscribe to.\n * @param whereClauseOrCallbacks - (Optional) Either a filter expression (where clause) or the callbacks object.\n * @param callbacks - (Optional) Callbacks for row insert, delete, and update events.\n *\n * @returns A snapshot object containing the current rows and the subscription state (`'loading'` or `'ready'`).\n *\n * @throws Error if the hook is used outside of a `SpacetimeDBProvider`.\n *\n * @example\n * ```tsx\n * const { rows, state } = useTable('users', where(eq('isActive', true)), {\n * onInsert: (row) => console.log('Inserted:', row),\n * onDelete: (row) => console.log('Deleted:', row),\n * onUpdate: (oldRow, newRow) => console.log('Updated:', oldRow, newRow),\n * });\n * ```\n */\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n where: Expr<ColumnsFromRow<RowType>>,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType>;\n\n/**\n * React hook to subscribe to a table in SpacetimeDB and receive live updates as rows are inserted, updated, or deleted.\n *\n * This hook returns a snapshot of the table's rows, filtered by an optional `where` clause, and provides a loading state\n * until the initial subscription is applied. It also allows you to specify callbacks for row insertions, deletions, and updates.\n *\n * The hook must be used within a component tree wrapped by `SpacetimeDBProvider`.\n *\n * Overloads:\n * - `useTable(tableName, where, callbacks?)`: Subscribe to a table with a filter and optional callbacks.\n * - `useTable(tableName, callbacks?)`: Subscribe to a table without a filter, with optional callbacks.\n *\n * @template DbConnection The type of the SpacetimeDB connection.\n * @template RowType The type of the table row.\n * @template TableName The name of the table.\n *\n * @param tableName - The name of the table to subscribe to.\n * @param whereClauseOrCallbacks - (Optional) Either a filter expression (where clause) or the callbacks object.\n * @param callbacks - (Optional) Callbacks for row insert, delete, and update events.\n *\n * @returns A snapshot object containing the current rows and the subscription state (`'loading'` or `'ready'`).\n *\n * @throws Error if the hook is used outside of a `SpacetimeDBProvider`.\n *\n * @example\n * ```tsx\n * const { rows, state } = useTable('users', where(eq('isActive', true)), {\n * onInsert: (row) => console.log('Inserted:', row),\n * onDelete: (row) => console.log('Deleted:', row),\n * onUpdate: (oldRow, newRow) => console.log('Updated:', oldRow, newRow),\n * });\n * ```\n */\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType>;\n\nexport function useTable<\n DbConnection extends DbConnectionImpl,\n RowType extends Record<string, any>,\n TableName extends keyof DbConnection['db'] &\n string = keyof DbConnection['db'] & string,\n>(\n tableName: TableName,\n whereClauseOrCallbacks?:\n | Expr<ColumnsFromRow<RowType>>\n | UseQueryCallbacks<RowType>,\n callbacks?: UseQueryCallbacks<RowType>\n): Snapshot<RowType> {\n let whereClause: Expr<ColumnsFromRow<RowType>> | undefined;\n if (\n whereClauseOrCallbacks &&\n typeof whereClauseOrCallbacks === 'object' &&\n 'type' in whereClauseOrCallbacks\n ) {\n whereClause = whereClauseOrCallbacks as Expr<ColumnsFromRow<RowType>>;\n } else {\n callbacks = whereClauseOrCallbacks as\n | UseQueryCallbacks<RowType>\n | undefined;\n }\n const [subscribeApplied, setSubscribeApplied] = useState(false);\n const [isActive, setIsActive] = useState(false);\n let spacetime: DbConnection | undefined;\n try {\n spacetime = useSpacetimeDB<DbConnection>();\n } catch {\n throw new Error(\n 'Could not find SpacetimeDB client! Did you forget to add a ' +\n '`SpacetimeDBProvider`? `useTable` must be used in the React component tree ' +\n 'under a `SpacetimeDBProvider` component.'\n );\n }\n const client = spacetime;\n\n const query =\n `SELECT * FROM ${tableName}` +\n (whereClause ? ` WHERE ${toString(whereClause)}` : '');\n\n const latestTransactionEvent = useRef<any>(null);\n const lastSnapshotRef = useRef<Snapshot<RowType> | null>(null);\n\n const whereKey = whereClause ? toString(whereClause) : '';\n\n const computeSnapshot = useCallback((): Snapshot<RowType> => {\n const table = client.db[\n tableName as keyof typeof client.db\n ] as unknown as TableCache<RowType>;\n const result: readonly RowType[] = whereClause\n ? table.iter().filter(row => evaluate(whereClause, row))\n : table.iter();\n return {\n rows: result,\n state: subscribeApplied ? 'ready' : 'loading',\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [client, tableName, whereKey, subscribeApplied]);\n\n useEffect(() => {\n const onConnect = () => {\n setIsActive(client.isActive);\n };\n const onDisconnect = () => {\n setIsActive(client.isActive);\n };\n const onConnectError = () => {\n setIsActive(client.isActive);\n };\n client['on']('connect', onConnect);\n client['on']('disconnect', onDisconnect);\n client['on']('connectError', onConnectError);\n return () => {\n client['off']('connect', onConnect);\n client['off']('disconnect', onDisconnect);\n client['off']('connectError', onConnectError);\n };\n }, [client]);\n\n useEffect(() => {\n if (isActive) {\n const cancel = client\n .subscriptionBuilder()\n .onApplied(() => {\n setSubscribeApplied(true);\n })\n .subscribe(query);\n return () => {\n cancel.unsubscribe();\n };\n }\n }, [query, isActive, client]);\n\n const subscribe = useCallback(\n (onStoreChange: () => void) => {\n const onInsert = (ctx: any, row: RowType) => {\n if (whereClause && !evaluate(whereClause, row)) {\n return;\n }\n if (tableName === 'message') {\n console.log('onInsert for messages table:', row);\n }\n callbacks?.onInsert?.(row);\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const onDelete = (ctx: any, row: RowType) => {\n if (whereClause && !evaluate(whereClause, row)) {\n return;\n }\n if (tableName === 'message') {\n console.log('onDelete for messages table:', row);\n }\n callbacks?.onDelete?.(row);\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const onUpdate = (ctx: any, oldRow: RowType, newRow: RowType) => {\n const change = classifyMembership(whereClause, oldRow, newRow);\n\n switch (change) {\n case 'leave':\n callbacks?.onDelete?.(oldRow);\n break;\n case 'enter':\n callbacks?.onInsert?.(newRow);\n break;\n case 'stayIn':\n callbacks?.onUpdate?.(oldRow, newRow);\n break;\n case 'stayOut':\n return; // no-op\n }\n\n if (\n ctx.event !== latestTransactionEvent.current ||\n !latestTransactionEvent.current\n ) {\n latestTransactionEvent.current = ctx.event;\n lastSnapshotRef.current = computeSnapshot();\n onStoreChange();\n }\n };\n\n const table = client.db[\n tableName as keyof typeof client.db\n ] as unknown as TableCache<RowType>;\n table.onInsert(onInsert);\n table.onDelete(onDelete);\n table.onUpdate?.(onUpdate);\n\n return () => {\n table.removeOnInsert(onInsert);\n table.removeOnDelete(onDelete);\n table.removeOnUpdate?.(onUpdate);\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n client,\n tableName,\n whereKey,\n callbacks?.onDelete,\n callbacks?.onInsert,\n callbacks?.onUpdate,\n ]\n );\n\n const getSnapshot = useCallback((): Snapshot<RowType> => {\n if (!lastSnapshotRef.current) {\n lastSnapshotRef.current = computeSnapshot();\n }\n return lastSnapshotRef.current;\n }, [computeSnapshot]);\n\n // SSR fallback can be the same getter\n return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Context } from 'react';
|
|
2
|
+
import type { DbConnectionImpl } from '../sdk/db_connection_impl';
|
|
3
|
+
export declare const SpacetimeDBContext: Context<DbConnectionImpl | undefined>;
|
|
4
|
+
export declare function useSpacetimeDB<DbConnection extends DbConnectionImpl>(): DbConnection;
|
|
5
|
+
//# sourceMappingURL=useSpacetimeDB.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSpacetimeDB.d.ts","sourceRoot":"","sources":["../../src/react/useSpacetimeDB.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,OAAO,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAElE,eAAO,MAAM,kBAAkB,EAAE,OAAO,CAAC,gBAAgB,GAAG,SAAS,CACb,CAAC;AAIzD,wBAAgB,cAAc,CAC5B,YAAY,SAAS,gBAAgB,KAClC,YAAY,CAQhB"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { DbConnectionImpl } from '../sdk/db_connection_impl';
|
|
2
|
+
export interface UseQueryCallbacks<RowType> {
|
|
3
|
+
onInsert?: (row: RowType) => void;
|
|
4
|
+
onDelete?: (row: RowType) => void;
|
|
5
|
+
onUpdate?: (oldRow: RowType, newRow: RowType) => void;
|
|
6
|
+
}
|
|
7
|
+
export type Value = string | number | boolean;
|
|
8
|
+
export type Expr<Column extends string> = {
|
|
9
|
+
type: 'eq';
|
|
10
|
+
key: Column;
|
|
11
|
+
value: Value;
|
|
12
|
+
} | {
|
|
13
|
+
type: 'and';
|
|
14
|
+
children: Expr<Column>[];
|
|
15
|
+
} | {
|
|
16
|
+
type: 'or';
|
|
17
|
+
children: Expr<Column>[];
|
|
18
|
+
};
|
|
19
|
+
export declare const eq: <Column extends string>(key: Column, value: Value) => Expr<Column>;
|
|
20
|
+
export declare const and: <Column extends string>(...children: Expr<Column>[]) => Expr<Column>;
|
|
21
|
+
export declare const or: <Column extends string>(...children: Expr<Column>[]) => Expr<Column>;
|
|
22
|
+
export declare const isEq: <Column extends string>(e: Expr<Column>) => e is Extract<Expr<Column>, {
|
|
23
|
+
type: "eq";
|
|
24
|
+
}>;
|
|
25
|
+
export declare const isAnd: <Column extends string>(e: Expr<Column>) => e is Extract<Expr<Column>, {
|
|
26
|
+
type: "and";
|
|
27
|
+
}>;
|
|
28
|
+
export declare const isOr: <Column extends string>(e: Expr<Column>) => e is Extract<Expr<Column>, {
|
|
29
|
+
type: "or";
|
|
30
|
+
}>;
|
|
31
|
+
type RecordLike<Column extends string> = Record<Column, unknown>;
|
|
32
|
+
export declare function evaluate<Column extends string>(expr: Expr<Column>, row: RecordLike<Column>): boolean;
|
|
33
|
+
export declare function toString<Column extends string>(expr: Expr<Column>): string;
|
|
34
|
+
/**
|
|
35
|
+
* This is just the identity function to make things look like SQL.
|
|
36
|
+
* @param expr
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export declare function where<Column extends string>(expr: Expr<Column>): Expr<Column>;
|
|
40
|
+
type Snapshot<RowType> = {
|
|
41
|
+
readonly rows: readonly RowType[];
|
|
42
|
+
readonly state: 'loading' | 'ready';
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Extracts the column names from a RowType whose values are of type Value.
|
|
46
|
+
* Note that this will exclude columns that are of type object, array, etc.
|
|
47
|
+
*/
|
|
48
|
+
type ColumnsFromRow<R> = {
|
|
49
|
+
[K in keyof R]-?: R[K] extends Value | undefined ? K : never;
|
|
50
|
+
}[keyof R] & string;
|
|
51
|
+
/**
|
|
52
|
+
* React hook to subscribe to a table in SpacetimeDB and receive live updates as rows are inserted, updated, or deleted.
|
|
53
|
+
*
|
|
54
|
+
* This hook returns a snapshot of the table's rows, filtered by an optional `where` clause, and provides a loading state
|
|
55
|
+
* until the initial subscription is applied. It also allows you to specify callbacks for row insertions, deletions, and updates.
|
|
56
|
+
*
|
|
57
|
+
* The hook must be used within a component tree wrapped by `SpacetimeDBProvider`.
|
|
58
|
+
*
|
|
59
|
+
* Overloads:
|
|
60
|
+
* - `useTable(tableName, where, callbacks?)`: Subscribe to a table with a filter and optional callbacks.
|
|
61
|
+
* - `useTable(tableName, callbacks?)`: Subscribe to a table without a filter, with optional callbacks.
|
|
62
|
+
*
|
|
63
|
+
* @template DbConnection The type of the SpacetimeDB connection.
|
|
64
|
+
* @template RowType The type of the table row.
|
|
65
|
+
* @template TableName The name of the table.
|
|
66
|
+
*
|
|
67
|
+
* @param tableName - The name of the table to subscribe to.
|
|
68
|
+
* @param whereClauseOrCallbacks - (Optional) Either a filter expression (where clause) or the callbacks object.
|
|
69
|
+
* @param callbacks - (Optional) Callbacks for row insert, delete, and update events.
|
|
70
|
+
*
|
|
71
|
+
* @returns A snapshot object containing the current rows and the subscription state (`'loading'` or `'ready'`).
|
|
72
|
+
*
|
|
73
|
+
* @throws Error if the hook is used outside of a `SpacetimeDBProvider`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* const { rows, state } = useTable('users', where(eq('isActive', true)), {
|
|
78
|
+
* onInsert: (row) => console.log('Inserted:', row),
|
|
79
|
+
* onDelete: (row) => console.log('Deleted:', row),
|
|
80
|
+
* onUpdate: (oldRow, newRow) => console.log('Updated:', oldRow, newRow),
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function useTable<DbConnection extends DbConnectionImpl, RowType extends Record<string, any>, TableName extends keyof DbConnection['db'] & string = keyof DbConnection['db'] & string>(tableName: TableName, where: Expr<ColumnsFromRow<RowType>>, callbacks?: UseQueryCallbacks<RowType>): Snapshot<RowType>;
|
|
85
|
+
/**
|
|
86
|
+
* React hook to subscribe to a table in SpacetimeDB and receive live updates as rows are inserted, updated, or deleted.
|
|
87
|
+
*
|
|
88
|
+
* This hook returns a snapshot of the table's rows, filtered by an optional `where` clause, and provides a loading state
|
|
89
|
+
* until the initial subscription is applied. It also allows you to specify callbacks for row insertions, deletions, and updates.
|
|
90
|
+
*
|
|
91
|
+
* The hook must be used within a component tree wrapped by `SpacetimeDBProvider`.
|
|
92
|
+
*
|
|
93
|
+
* Overloads:
|
|
94
|
+
* - `useTable(tableName, where, callbacks?)`: Subscribe to a table with a filter and optional callbacks.
|
|
95
|
+
* - `useTable(tableName, callbacks?)`: Subscribe to a table without a filter, with optional callbacks.
|
|
96
|
+
*
|
|
97
|
+
* @template DbConnection The type of the SpacetimeDB connection.
|
|
98
|
+
* @template RowType The type of the table row.
|
|
99
|
+
* @template TableName The name of the table.
|
|
100
|
+
*
|
|
101
|
+
* @param tableName - The name of the table to subscribe to.
|
|
102
|
+
* @param whereClauseOrCallbacks - (Optional) Either a filter expression (where clause) or the callbacks object.
|
|
103
|
+
* @param callbacks - (Optional) Callbacks for row insert, delete, and update events.
|
|
104
|
+
*
|
|
105
|
+
* @returns A snapshot object containing the current rows and the subscription state (`'loading'` or `'ready'`).
|
|
106
|
+
*
|
|
107
|
+
* @throws Error if the hook is used outside of a `SpacetimeDBProvider`.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```tsx
|
|
111
|
+
* const { rows, state } = useTable('users', where(eq('isActive', true)), {
|
|
112
|
+
* onInsert: (row) => console.log('Inserted:', row),
|
|
113
|
+
* onDelete: (row) => console.log('Deleted:', row),
|
|
114
|
+
* onUpdate: (oldRow, newRow) => console.log('Updated:', oldRow, newRow),
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function useTable<DbConnection extends DbConnectionImpl, RowType extends Record<string, any>, TableName extends keyof DbConnection['db'] & string = keyof DbConnection['db'] & string>(tableName: TableName, callbacks?: UseQueryCallbacks<RowType>): Snapshot<RowType>;
|
|
119
|
+
export {};
|
|
120
|
+
//# sourceMappingURL=useTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTable.d.ts","sourceRoot":"","sources":["../../src/react/useTable.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAc,MAAM,2BAA2B,CAAC;AAEzE,MAAM,WAAW,iBAAiB,CAAC,OAAO;IACxC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACvD;AAED,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE9C,MAAM,MAAM,IAAI,CAAC,MAAM,SAAS,MAAM,IAClC;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,QAAQ,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CAAC,EACnC,SAAS,SAAS,MAAM,YAAY,CAAC,IAAI,CAAC,GACxC,MAAM,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,EAE5C,SAAS,EAAE,SAAS,EACpB,SAAS,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACrC,QAAQ,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BinaryReader as __BinaryReader, BinaryWriter as __BinaryWriter, type AlgebraicType as __AlgebraicTypeType } from '../../index';
|
|
2
|
+
import { RowSizeHint } from './row_size_hint_type';
|
|
3
|
+
export type BsatnRowList = {
|
|
4
|
+
sizeHint: RowSizeHint;
|
|
5
|
+
rowsData: Uint8Array;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* An object for generated helper functions.
|
|
9
|
+
*/
|
|
10
|
+
export declare const BsatnRowList: {
|
|
11
|
+
/**
|
|
12
|
+
* A function which returns this type represented as an AlgebraicType.
|
|
13
|
+
* This function is derived from the AlgebraicType used to generate this type.
|
|
14
|
+
*/
|
|
15
|
+
getTypeScriptAlgebraicType(): __AlgebraicTypeType;
|
|
16
|
+
serialize(writer: __BinaryWriter, value: BsatnRowList): void;
|
|
17
|
+
deserialize(reader: __BinaryReader): BsatnRowList;
|
|
18
|
+
};
|
|
19
|
+
export default BsatnRowList;
|
|
20
|
+
//# sourceMappingURL=bsatn_row_list_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bsatn_row_list_type.d.ts","sourceRoot":"","sources":["../../../src/sdk/client_api/bsatn_row_list_type.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,YAAY,IAAI,cAAc,EAC9B,YAAY,IAAI,cAAc,EAW9B,KAAK,aAAa,IAAI,mBAAmB,EAQ1C,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,WAAW,CAAC;IACtB,QAAQ,EAAE,UAAU,CAAC;CACtB,CAAC;AACF;;GAEG;AACH,eAAO,MAAM,YAAY;IACvB;;;OAGG;kCAC2B,mBAAmB;sBAe/B,cAAc,SAAS,YAAY,GAAG,IAAI;wBAQxC,cAAc,GAAG,YAAY;CAMlD,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BinaryReader as __BinaryReader, BinaryWriter as __BinaryWriter, type AlgebraicType as __AlgebraicTypeType } from '../../index';
|
|
2
|
+
export type CallReducer = {
|
|
3
|
+
reducer: string;
|
|
4
|
+
args: Uint8Array;
|
|
5
|
+
requestId: number;
|
|
6
|
+
flags: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* An object for generated helper functions.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CallReducer: {
|
|
12
|
+
/**
|
|
13
|
+
* A function which returns this type represented as an AlgebraicType.
|
|
14
|
+
* This function is derived from the AlgebraicType used to generate this type.
|
|
15
|
+
*/
|
|
16
|
+
getTypeScriptAlgebraicType(): __AlgebraicTypeType;
|
|
17
|
+
serialize(writer: __BinaryWriter, value: CallReducer): void;
|
|
18
|
+
deserialize(reader: __BinaryReader): CallReducer;
|
|
19
|
+
};
|
|
20
|
+
export default CallReducer;
|
|
21
|
+
//# sourceMappingURL=call_reducer_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call_reducer_type.d.ts","sourceRoot":"","sources":["../../../src/sdk/client_api/call_reducer_type.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,YAAY,IAAI,cAAc,EAC9B,YAAY,IAAI,cAAc,EAW9B,KAAK,aAAa,IAAI,mBAAmB,EAQ1C,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AACF;;GAEG;AACH,eAAO,MAAM,WAAW;IACtB;;;OAGG;kCAC2B,mBAAmB;sBAc/B,cAAc,SAAS,WAAW,GAAG,IAAI;wBAQvC,cAAc,GAAG,WAAW;CAMjD,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BinaryReader as __BinaryReader, BinaryWriter as __BinaryWriter, type AlgebraicType as __AlgebraicTypeType } from '../../index';
|
|
2
|
+
import { CallReducer } from './call_reducer_type';
|
|
3
|
+
import { Subscribe } from './subscribe_type';
|
|
4
|
+
import { OneOffQuery } from './one_off_query_type';
|
|
5
|
+
import { SubscribeSingle } from './subscribe_single_type';
|
|
6
|
+
import { SubscribeMulti } from './subscribe_multi_type';
|
|
7
|
+
import { Unsubscribe } from './unsubscribe_type';
|
|
8
|
+
import { UnsubscribeMulti } from './unsubscribe_multi_type';
|
|
9
|
+
import * as ClientMessageVariants from './client_message_variants';
|
|
10
|
+
export type ClientMessage = ClientMessageVariants.CallReducer | ClientMessageVariants.Subscribe | ClientMessageVariants.OneOffQuery | ClientMessageVariants.SubscribeSingle | ClientMessageVariants.SubscribeMulti | ClientMessageVariants.Unsubscribe | ClientMessageVariants.UnsubscribeMulti;
|
|
11
|
+
export declare const ClientMessage: {
|
|
12
|
+
CallReducer: (value: CallReducer) => ClientMessage;
|
|
13
|
+
Subscribe: (value: Subscribe) => ClientMessage;
|
|
14
|
+
OneOffQuery: (value: OneOffQuery) => ClientMessage;
|
|
15
|
+
SubscribeSingle: (value: SubscribeSingle) => ClientMessage;
|
|
16
|
+
SubscribeMulti: (value: SubscribeMulti) => ClientMessage;
|
|
17
|
+
Unsubscribe: (value: Unsubscribe) => ClientMessage;
|
|
18
|
+
UnsubscribeMulti: (value: UnsubscribeMulti) => ClientMessage;
|
|
19
|
+
getTypeScriptAlgebraicType(): __AlgebraicTypeType;
|
|
20
|
+
serialize(writer: __BinaryWriter, value: ClientMessage): void;
|
|
21
|
+
deserialize(reader: __BinaryReader): ClientMessage;
|
|
22
|
+
};
|
|
23
|
+
export default ClientMessage;
|
|
24
|
+
//# sourceMappingURL=client_message_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client_message_type.d.ts","sourceRoot":"","sources":["../../../src/sdk/client_api/client_message_type.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,YAAY,IAAI,cAAc,EAC9B,YAAY,IAAI,cAAc,EAW9B,KAAK,aAAa,IAAI,mBAAmB,EAQ1C,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG1D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAI5D,OAAO,KAAK,qBAAqB,MAAM,2BAA2B,CAAC;AAGnE,MAAM,MAAM,aAAa,GACrB,qBAAqB,CAAC,WAAW,GACjC,qBAAqB,CAAC,SAAS,GAC/B,qBAAqB,CAAC,WAAW,GACjC,qBAAqB,CAAC,eAAe,GACrC,qBAAqB,CAAC,cAAc,GACpC,qBAAqB,CAAC,WAAW,GACjC,qBAAqB,CAAC,gBAAgB,CAAC;AAG3C,eAAO,MAAM,aAAa;yBAOH,WAAW,KAAG,aAAa;uBAI7B,SAAS,KAAG,aAAa;yBACvB,WAAW,KAAG,aAAa;6BAIvB,eAAe,KAAG,aAAa;4BAIhC,cAAc,KAAG,aAAa;yBAIjC,WAAW,KAAG,aAAa;8BAItB,gBAAgB,KAAG,aAAa;kCAK5B,mBAAmB;sBAmC/B,cAAc,SAAS,aAAa,GAAG,IAAI;wBAQzC,cAAc,GAAG,aAAa;CAMnD,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CallReducer as CallReducerType } from './call_reducer_type';
|
|
2
|
+
import { Subscribe as SubscribeType } from './subscribe_type';
|
|
3
|
+
import { OneOffQuery as OneOffQueryType } from './one_off_query_type';
|
|
4
|
+
import { SubscribeSingle as SubscribeSingleType } from './subscribe_single_type';
|
|
5
|
+
import { SubscribeMulti as SubscribeMultiType } from './subscribe_multi_type';
|
|
6
|
+
import { Unsubscribe as UnsubscribeType } from './unsubscribe_type';
|
|
7
|
+
import { UnsubscribeMulti as UnsubscribeMultiType } from './unsubscribe_multi_type';
|
|
8
|
+
export type CallReducer = {
|
|
9
|
+
tag: 'CallReducer';
|
|
10
|
+
value: CallReducerType;
|
|
11
|
+
};
|
|
12
|
+
export type Subscribe = {
|
|
13
|
+
tag: 'Subscribe';
|
|
14
|
+
value: SubscribeType;
|
|
15
|
+
};
|
|
16
|
+
export type OneOffQuery = {
|
|
17
|
+
tag: 'OneOffQuery';
|
|
18
|
+
value: OneOffQueryType;
|
|
19
|
+
};
|
|
20
|
+
export type SubscribeSingle = {
|
|
21
|
+
tag: 'SubscribeSingle';
|
|
22
|
+
value: SubscribeSingleType;
|
|
23
|
+
};
|
|
24
|
+
export type SubscribeMulti = {
|
|
25
|
+
tag: 'SubscribeMulti';
|
|
26
|
+
value: SubscribeMultiType;
|
|
27
|
+
};
|
|
28
|
+
export type Unsubscribe = {
|
|
29
|
+
tag: 'Unsubscribe';
|
|
30
|
+
value: UnsubscribeType;
|
|
31
|
+
};
|
|
32
|
+
export type UnsubscribeMulti = {
|
|
33
|
+
tag: 'UnsubscribeMulti';
|
|
34
|
+
value: UnsubscribeMultiType;
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=client_message_variants.d.ts.map
|
|
@@ -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,GAAG,EAAE,kBAAkB,CAAC;IACxB,KAAK,EAAE,oBAAoB,CAAC;CAC7B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BinaryReader as __BinaryReader, BinaryWriter as __BinaryWriter, type AlgebraicType as __AlgebraicTypeType } from '../../index';
|
|
2
|
+
import { QueryUpdate } from './query_update_type';
|
|
3
|
+
import * as CompressableQueryUpdateVariants from './compressable_query_update_variants';
|
|
4
|
+
export type CompressableQueryUpdate = CompressableQueryUpdateVariants.Uncompressed | CompressableQueryUpdateVariants.Brotli | CompressableQueryUpdateVariants.Gzip;
|
|
5
|
+
export declare const CompressableQueryUpdate: {
|
|
6
|
+
Uncompressed: (value: QueryUpdate) => CompressableQueryUpdate;
|
|
7
|
+
Brotli: (value: Uint8Array) => CompressableQueryUpdate;
|
|
8
|
+
Gzip: (value: Uint8Array) => CompressableQueryUpdate;
|
|
9
|
+
getTypeScriptAlgebraicType(): __AlgebraicTypeType;
|
|
10
|
+
serialize(writer: __BinaryWriter, value: CompressableQueryUpdate): void;
|
|
11
|
+
deserialize(reader: __BinaryReader): CompressableQueryUpdate;
|
|
12
|
+
};
|
|
13
|
+
export default CompressableQueryUpdate;
|
|
14
|
+
//# sourceMappingURL=compressable_query_update_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compressable_query_update_type.d.ts","sourceRoot":"","sources":["../../../src/sdk/client_api/compressable_query_update_type.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,YAAY,IAAI,cAAc,EAC9B,YAAY,IAAI,cAAc,EAW9B,KAAK,aAAa,IAAI,mBAAmB,EAQ1C,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIlD,OAAO,KAAK,+BAA+B,MAAM,sCAAsC,CAAC;AAGxF,MAAM,MAAM,uBAAuB,GAC/B,+BAA+B,CAAC,YAAY,GAC5C,+BAA+B,CAAC,MAAM,GACtC,+BAA+B,CAAC,IAAI,CAAC;AAGzC,eAAO,MAAM,uBAAuB;0BAOZ,WAAW,KAAG,uBAAuB;oBAI3C,UAAU,KAAG,uBAAuB;kBAItC,UAAU,KAAG,uBAAuB;kCAKpB,mBAAmB;sBAmB/B,cAAc,SAAS,uBAAuB,GAAG,IAAI;wBAQnD,cAAc,GAAG,uBAAuB;CAM7D,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { QueryUpdate as QueryUpdateType } from './query_update_type';
|
|
2
|
+
export type Uncompressed = {
|
|
3
|
+
tag: 'Uncompressed';
|
|
4
|
+
value: QueryUpdateType;
|
|
5
|
+
};
|
|
6
|
+
export type Brotli = {
|
|
7
|
+
tag: 'Brotli';
|
|
8
|
+
value: Uint8Array;
|
|
9
|
+
};
|
|
10
|
+
export type Gzip = {
|
|
11
|
+
tag: 'Gzip';
|
|
12
|
+
value: Uint8Array;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=compressable_query_update_variants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compressable_query_update_variants.d.ts","sourceRoot":"","sources":["../../../src/sdk/client_api/compressable_query_update_variants.ts"],"names":[],"mappings":"AA4BA,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAIrE,MAAM,MAAM,YAAY,GAAG;IAAE,GAAG,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,CAAC;AAC3E,MAAM,MAAM,MAAM,GAAG;IAAE,GAAG,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC;AAC1D,MAAM,MAAM,IAAI,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BinaryReader as __BinaryReader, BinaryWriter as __BinaryWriter, type AlgebraicType as __AlgebraicTypeType } from '../../index';
|
|
2
|
+
import { TableUpdate } from './table_update_type';
|
|
3
|
+
export type DatabaseUpdate = {
|
|
4
|
+
tables: TableUpdate[];
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* An object for generated helper functions.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DatabaseUpdate: {
|
|
10
|
+
/**
|
|
11
|
+
* A function which returns this type represented as an AlgebraicType.
|
|
12
|
+
* This function is derived from the AlgebraicType used to generate this type.
|
|
13
|
+
*/
|
|
14
|
+
getTypeScriptAlgebraicType(): __AlgebraicTypeType;
|
|
15
|
+
serialize(writer: __BinaryWriter, value: DatabaseUpdate): void;
|
|
16
|
+
deserialize(reader: __BinaryReader): DatabaseUpdate;
|
|
17
|
+
};
|
|
18
|
+
export default DatabaseUpdate;
|
|
19
|
+
//# sourceMappingURL=database_update_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database_update_type.d.ts","sourceRoot":"","sources":["../../../src/sdk/client_api/database_update_type.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,YAAY,IAAI,cAAc,EAC9B,YAAY,IAAI,cAAc,EAW9B,KAAK,aAAa,IAAI,mBAAmB,EAQ1C,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIlD,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB,CAAC;AACF;;GAEG;AACH,eAAO,MAAM,cAAc;IACzB;;;OAGG;kCAC2B,mBAAmB;sBAa/B,cAAc,SAAS,cAAc,GAAG,IAAI;wBAQ1C,cAAc,GAAG,cAAc;CAMpD,CAAC;AAEF,eAAe,cAAc,CAAC"}
|