@geoprotocol/geo-sdk 0.18.3 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +995 -372
- package/dist/contracts.d.ts +0 -11
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +0 -11
- package/dist/contracts.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/lite.d.ts +2 -0
- package/dist/lite.d.ts.map +1 -1
- package/dist/lite.js +2 -0
- package/dist/lite.js.map +1 -1
- package/dist/src/abis/dao-space-v2.test.d.ts +2 -0
- package/dist/src/abis/dao-space-v2.test.d.ts.map +1 -0
- package/dist/src/abis/dao-space-v2.test.js +67 -0
- package/dist/src/abis/dao-space-v2.test.js.map +1 -0
- package/dist/src/client/api.d.ts +86 -0
- package/dist/src/client/api.d.ts.map +1 -0
- package/dist/src/client/api.js +169 -0
- package/dist/src/client/api.js.map +1 -0
- package/dist/src/client/comments.d.ts +59 -0
- package/dist/src/client/comments.d.ts.map +1 -0
- package/dist/src/client/comments.js +96 -0
- package/dist/src/client/comments.js.map +1 -0
- package/dist/src/client/context.d.ts +20 -0
- package/dist/src/client/context.d.ts.map +1 -0
- package/dist/src/client/context.js +20 -0
- package/dist/src/client/context.js.map +1 -0
- package/dist/src/client/dao-spaces.d.ts +348 -0
- package/dist/src/client/dao-spaces.d.ts.map +1 -0
- package/dist/src/client/dao-spaces.js +494 -0
- package/dist/src/client/dao-spaces.js.map +1 -0
- package/dist/src/client/dao-spaces.test.d.ts +2 -0
- package/dist/src/client/dao-spaces.test.d.ts.map +1 -0
- package/dist/src/client/dao-spaces.test.js +263 -0
- package/dist/src/client/dao-spaces.test.js.map +1 -0
- package/dist/src/client/edits.d.ts +100 -0
- package/dist/src/client/edits.d.ts.map +1 -0
- package/dist/src/client/edits.js +131 -0
- package/dist/src/client/edits.js.map +1 -0
- package/dist/src/client/edits.test.d.ts +2 -0
- package/dist/src/client/edits.test.d.ts.map +1 -0
- package/dist/src/client/edits.test.js +98 -0
- package/dist/src/client/edits.test.js.map +1 -0
- package/dist/src/client/entities.d.ts +23 -0
- package/dist/src/client/entities.d.ts.map +1 -0
- package/dist/src/client/entities.js +88 -0
- package/dist/src/client/entities.js.map +1 -0
- package/dist/src/client/entity-votes.d.ts +141 -0
- package/dist/src/client/entity-votes.d.ts.map +1 -0
- package/dist/src/client/entity-votes.js +168 -0
- package/dist/src/client/entity-votes.js.map +1 -0
- package/dist/src/client/entity-votes.test.d.ts +2 -0
- package/dist/src/client/entity-votes.test.d.ts.map +1 -0
- package/dist/src/client/entity-votes.test.js +93 -0
- package/dist/src/client/entity-votes.test.js.map +1 -0
- package/dist/src/client/graph-workflows.test.d.ts +2 -0
- package/dist/src/client/graph-workflows.test.d.ts.map +1 -0
- package/dist/src/client/graph-workflows.test.js +83 -0
- package/dist/src/client/graph-workflows.test.js.map +1 -0
- package/dist/src/client/images-storage.test.d.ts +2 -0
- package/dist/src/client/images-storage.test.d.ts.map +1 -0
- package/dist/src/client/images-storage.test.js +52 -0
- package/dist/src/client/images-storage.test.js.map +1 -0
- package/dist/src/client/images.d.ts +35 -0
- package/dist/src/client/images.d.ts.map +1 -0
- package/dist/src/client/images.js +90 -0
- package/dist/src/client/images.js.map +1 -0
- package/dist/src/client/personal-spaces.d.ts +155 -0
- package/dist/src/client/personal-spaces.d.ts.map +1 -0
- package/dist/src/client/personal-spaces.js +198 -0
- package/dist/src/client/personal-spaces.js.map +1 -0
- package/dist/src/client/proposals.d.ts +185 -0
- package/dist/src/client/proposals.d.ts.map +1 -0
- package/dist/src/client/proposals.js +294 -0
- package/dist/src/client/proposals.js.map +1 -0
- package/dist/src/client/proposals.test.d.ts +2 -0
- package/dist/src/client/proposals.test.d.ts.map +1 -0
- package/dist/src/client/proposals.test.js +243 -0
- package/dist/src/client/proposals.test.js.map +1 -0
- package/dist/src/client/spaces.test.d.ts +2 -0
- package/dist/src/client/spaces.test.d.ts.map +1 -0
- package/dist/src/client/spaces.test.js +155 -0
- package/dist/src/client/spaces.test.js.map +1 -0
- package/dist/src/client/storage.d.ts +52 -0
- package/dist/src/client/storage.d.ts.map +1 -0
- package/dist/src/client/storage.js +53 -0
- package/dist/src/client/storage.js.map +1 -0
- package/dist/src/client.d.ts +325 -0
- package/dist/src/client.d.ts.map +1 -0
- package/dist/src/client.js +452 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/client.test.d.ts +2 -0
- package/dist/src/client.test.d.ts.map +1 -0
- package/dist/src/client.test.js +120 -0
- package/dist/src/client.test.js.map +1 -0
- package/dist/src/contracts-v2/abis.d.ts +196 -0
- package/dist/src/contracts-v2/abis.d.ts.map +1 -0
- package/dist/src/contracts-v2/abis.js +110 -0
- package/dist/src/contracts-v2/abis.js.map +1 -0
- package/dist/src/contracts-v2/actions.d.ts +56 -0
- package/dist/src/contracts-v2/actions.d.ts.map +1 -0
- package/dist/src/contracts-v2/actions.js +83 -0
- package/dist/src/contracts-v2/actions.js.map +1 -0
- package/dist/src/contracts-v2/encoding.d.ts +80 -0
- package/dist/src/contracts-v2/encoding.d.ts.map +1 -0
- package/dist/src/contracts-v2/encoding.js +193 -0
- package/dist/src/contracts-v2/encoding.js.map +1 -0
- package/dist/src/contracts-v2/encoding.test.d.ts +2 -0
- package/dist/src/contracts-v2/encoding.test.d.ts.map +1 -0
- package/dist/src/contracts-v2/encoding.test.js +93 -0
- package/dist/src/contracts-v2/encoding.test.js.map +1 -0
- package/dist/src/contracts-v2/local-geobrowser.e2e.test.d.ts +2 -0
- package/dist/src/contracts-v2/local-geobrowser.e2e.test.d.ts.map +1 -0
- package/dist/src/contracts-v2/local-geobrowser.e2e.test.js +239 -0
- package/dist/src/contracts-v2/local-geobrowser.e2e.test.js.map +1 -0
- package/dist/src/contracts-v2/voting-settings.d.ts +48 -0
- package/dist/src/contracts-v2/voting-settings.d.ts.map +1 -0
- package/dist/src/contracts-v2/voting-settings.js +69 -0
- package/dist/src/contracts-v2/voting-settings.js.map +1 -0
- package/dist/src/dao-space/constants.d.ts +6 -3
- package/dist/src/dao-space/constants.d.ts.map +1 -1
- package/dist/src/dao-space/constants.js +6 -5
- package/dist/src/dao-space/constants.js.map +1 -1
- package/dist/src/dao-space/create-space.d.ts +1 -31
- package/dist/src/dao-space/create-space.d.ts.map +1 -1
- package/dist/src/dao-space/create-space.js +5 -70
- package/dist/src/dao-space/create-space.js.map +1 -1
- package/dist/src/dao-space/execute-proposal.d.ts +1 -22
- package/dist/src/dao-space/execute-proposal.d.ts.map +1 -1
- package/dist/src/dao-space/execute-proposal.js +12 -59
- package/dist/src/dao-space/execute-proposal.js.map +1 -1
- package/dist/src/dao-space/propose-add-editor.test.js +1 -1
- package/dist/src/dao-space/propose-add-editor.test.js.map +1 -1
- package/dist/src/dao-space/propose-edit.d.ts +1 -30
- package/dist/src/dao-space/propose-edit.d.ts.map +1 -1
- package/dist/src/dao-space/propose-edit.js +12 -108
- package/dist/src/dao-space/propose-edit.js.map +1 -1
- package/dist/src/dao-space/propose-edit.test.js +8 -1
- package/dist/src/dao-space/propose-edit.test.js.map +1 -1
- package/dist/src/dao-space/propose-remove-editor.d.ts.map +1 -1
- package/dist/src/dao-space/propose-remove-editor.js +5 -5
- package/dist/src/dao-space/propose-remove-editor.js.map +1 -1
- package/dist/src/dao-space/propose-remove-editor.test.js +3 -8
- package/dist/src/dao-space/propose-remove-editor.test.js.map +1 -1
- package/dist/src/dao-space/propose-remove-member.d.ts.map +1 -1
- package/dist/src/dao-space/propose-remove-member.js +5 -5
- package/dist/src/dao-space/propose-remove-member.js.map +1 -1
- package/dist/src/dao-space/propose-request-membership.d.ts.map +1 -1
- package/dist/src/dao-space/propose-request-membership.js +4 -4
- package/dist/src/dao-space/propose-request-membership.js.map +1 -1
- package/dist/src/dao-space/propose-update-voting-settings.d.ts +8 -0
- package/dist/src/dao-space/propose-update-voting-settings.d.ts.map +1 -0
- package/dist/src/dao-space/propose-update-voting-settings.js +19 -0
- package/dist/src/dao-space/propose-update-voting-settings.js.map +1 -0
- package/dist/src/dao-space/propose-update-voting-settings.test.d.ts +2 -0
- package/dist/src/dao-space/propose-update-voting-settings.test.d.ts.map +1 -0
- package/dist/src/dao-space/propose-update-voting-settings.test.js +118 -0
- package/dist/src/dao-space/propose-update-voting-settings.test.js.map +1 -0
- package/dist/src/dao-space/vote-proposal.d.ts +1 -24
- package/dist/src/dao-space/vote-proposal.d.ts.map +1 -1
- package/dist/src/dao-space/vote-proposal.js +12 -64
- package/dist/src/dao-space/vote-proposal.js.map +1 -1
- package/dist/src/e2e/local-geobrowser.d.ts +9 -0
- package/dist/src/e2e/local-geobrowser.d.ts.map +1 -0
- package/dist/src/e2e/local-geobrowser.js +35 -0
- package/dist/src/e2e/local-geobrowser.js.map +1 -0
- package/dist/src/e2e/v2-contracts.test.d.ts +2 -0
- package/dist/src/e2e/v2-contracts.test.d.ts.map +1 -0
- package/dist/src/e2e/v2-contracts.test.js +25 -0
- package/dist/src/e2e/v2-contracts.test.js.map +1 -0
- package/dist/src/e2e-api-surface.test.d.ts +2 -0
- package/dist/src/e2e-api-surface.test.d.ts.map +1 -0
- package/dist/src/e2e-api-surface.test.js +1021 -0
- package/dist/src/e2e-api-surface.test.js.map +1 -0
- package/dist/src/e2e-flows.test.d.ts +2 -0
- package/dist/src/e2e-flows.test.d.ts.map +1 -0
- package/dist/src/e2e-flows.test.js +445 -0
- package/dist/src/e2e-flows.test.js.map +1 -0
- package/dist/src/e2e-legacy-api-surface.test.d.ts +2 -0
- package/dist/src/e2e-legacy-api-surface.test.d.ts.map +1 -0
- package/dist/src/e2e-legacy-api-surface.test.js +840 -0
- package/dist/src/e2e-legacy-api-surface.test.js.map +1 -0
- package/dist/src/encoding.d.ts +3 -0
- package/dist/src/encoding.d.ts.map +1 -1
- package/dist/src/encoding.js +3 -0
- package/dist/src/encoding.js.map +1 -1
- package/dist/src/encodings/get-create-dao-space-calldata.d.ts +3 -89
- package/dist/src/encodings/get-create-dao-space-calldata.d.ts.map +1 -1
- package/dist/src/encodings/get-create-dao-space-calldata.js +5 -95
- package/dist/src/encodings/get-create-dao-space-calldata.js.map +1 -1
- package/dist/src/encodings/get-create-personal-space-calldata.d.ts +2 -0
- package/dist/src/encodings/get-create-personal-space-calldata.d.ts.map +1 -1
- package/dist/src/encodings/get-create-personal-space-calldata.js +2 -0
- package/dist/src/encodings/get-create-personal-space-calldata.js.map +1 -1
- package/dist/src/graph/comment-utils.d.ts +4 -0
- package/dist/src/graph/comment-utils.d.ts.map +1 -1
- package/dist/src/graph/comment-utils.js +4 -0
- package/dist/src/graph/comment-utils.js.map +1 -1
- package/dist/src/graph/constants.d.ts +12 -3
- package/dist/src/graph/constants.d.ts.map +1 -1
- package/dist/src/graph/constants.js +11 -5
- package/dist/src/graph/constants.js.map +1 -1
- package/dist/src/graph/create-comment.d.ts +3 -22
- package/dist/src/graph/create-comment.d.ts.map +1 -1
- package/dist/src/graph/create-comment.js +6 -136
- package/dist/src/graph/create-comment.js.map +1 -1
- package/dist/src/graph/create-comment.test.js +19 -8
- package/dist/src/graph/create-comment.test.js.map +1 -1
- package/dist/src/graph/create-entity.d.ts +2 -0
- package/dist/src/graph/create-entity.d.ts.map +1 -1
- package/dist/src/graph/create-entity.js +2 -0
- package/dist/src/graph/create-entity.js.map +1 -1
- package/dist/src/graph/create-image.d.ts +2 -21
- package/dist/src/graph/create-image.d.ts.map +1 -1
- package/dist/src/graph/create-image.js +7 -69
- package/dist/src/graph/create-image.js.map +1 -1
- package/dist/src/graph/create-property.d.ts +2 -0
- package/dist/src/graph/create-property.d.ts.map +1 -1
- package/dist/src/graph/create-property.js +2 -0
- package/dist/src/graph/create-property.js.map +1 -1
- package/dist/src/graph/create-proposal-review.d.ts +1 -27
- package/dist/src/graph/create-proposal-review.d.ts.map +1 -1
- package/dist/src/graph/create-proposal-review.js +4 -61
- package/dist/src/graph/create-proposal-review.js.map +1 -1
- package/dist/src/graph/create-relation.d.ts +2 -0
- package/dist/src/graph/create-relation.d.ts.map +1 -1
- package/dist/src/graph/create-relation.js +2 -0
- package/dist/src/graph/create-relation.js.map +1 -1
- package/dist/src/graph/create-type.d.ts +2 -0
- package/dist/src/graph/create-type.d.ts.map +1 -1
- package/dist/src/graph/create-type.js +2 -0
- package/dist/src/graph/create-type.js.map +1 -1
- package/dist/src/graph/delete-entity.d.ts +2 -14
- package/dist/src/graph/delete-entity.d.ts.map +1 -1
- package/dist/src/graph/delete-entity.js +5 -78
- package/dist/src/graph/delete-entity.js.map +1 -1
- package/dist/src/graph/delete-entity.test.js +7 -0
- package/dist/src/graph/delete-entity.test.js.map +1 -1
- package/dist/src/graph/delete-relation.d.ts +2 -0
- package/dist/src/graph/delete-relation.d.ts.map +1 -1
- package/dist/src/graph/delete-relation.js +2 -0
- package/dist/src/graph/delete-relation.js.map +1 -1
- package/dist/src/graph/entity-vote.d.ts +3 -3
- package/dist/src/graph/entity-vote.d.ts.map +1 -1
- package/dist/src/graph/entity-vote.js +21 -46
- package/dist/src/graph/entity-vote.js.map +1 -1
- package/dist/src/graph/update-comment.d.ts +3 -0
- package/dist/src/graph/update-comment.d.ts.map +1 -1
- package/dist/src/graph/update-comment.js +3 -0
- package/dist/src/graph/update-comment.js.map +1 -1
- package/dist/src/graph/update-entity.d.ts +2 -0
- package/dist/src/graph/update-entity.d.ts.map +1 -1
- package/dist/src/graph/update-entity.js +2 -0
- package/dist/src/graph/update-entity.js.map +1 -1
- package/dist/src/graph/update-proposal-review.d.ts +2 -27
- package/dist/src/graph/update-proposal-review.d.ts.map +1 -1
- package/dist/src/graph/update-proposal-review.js +4 -50
- package/dist/src/graph/update-proposal-review.js.map +1 -1
- package/dist/src/graph/update-relation.d.ts +2 -0
- package/dist/src/graph/update-relation.d.ts.map +1 -1
- package/dist/src/graph/update-relation.js +2 -0
- package/dist/src/graph/update-relation.js.map +1 -1
- package/dist/src/ipfs-core.d.ts +42 -0
- package/dist/src/ipfs-core.d.ts.map +1 -0
- package/dist/src/ipfs-core.js +165 -0
- package/dist/src/ipfs-core.js.map +1 -0
- package/dist/src/ipfs-core.test.d.ts +2 -0
- package/dist/src/ipfs-core.test.d.ts.map +1 -0
- package/dist/src/ipfs-core.test.js +56 -0
- package/dist/src/ipfs-core.test.js.map +1 -0
- package/dist/src/ipfs.d.ts +7 -52
- package/dist/src/ipfs.d.ts.map +1 -1
- package/dist/src/ipfs.js +27 -170
- package/dist/src/ipfs.js.map +1 -1
- package/dist/src/networks.d.ts +46 -0
- package/dist/src/networks.d.ts.map +1 -0
- package/dist/src/networks.js +90 -0
- package/dist/src/networks.js.map +1 -0
- package/dist/src/ops/comments.d.ts +80 -0
- package/dist/src/ops/comments.d.ts.map +1 -0
- package/dist/src/ops/comments.js +142 -0
- package/dist/src/ops/comments.js.map +1 -0
- package/dist/src/ops/entities.d.ts +50 -0
- package/dist/src/ops/entities.d.ts.map +1 -0
- package/dist/src/ops/entities.js +51 -0
- package/dist/src/ops/entities.js.map +1 -0
- package/dist/src/ops/images.d.ts +37 -0
- package/dist/src/ops/images.d.ts.map +1 -0
- package/dist/src/ops/images.js +69 -0
- package/dist/src/ops/images.js.map +1 -0
- package/dist/src/ops/index.d.ts +7 -0
- package/dist/src/ops/index.d.ts.map +1 -0
- package/dist/src/ops/index.js +7 -0
- package/dist/src/ops/index.js.map +1 -0
- package/dist/src/ops/index.test.d.ts +2 -0
- package/dist/src/ops/index.test.d.ts.map +1 -0
- package/dist/src/ops/index.test.js +115 -0
- package/dist/src/ops/index.test.js.map +1 -0
- package/dist/src/ops/properties.d.ts +20 -0
- package/dist/src/ops/properties.d.ts.map +1 -0
- package/dist/src/ops/properties.js +20 -0
- package/dist/src/ops/properties.js.map +1 -0
- package/dist/src/ops/proposal-reviews.d.ts +43 -0
- package/dist/src/ops/proposal-reviews.d.ts.map +1 -0
- package/dist/src/ops/proposal-reviews.js +103 -0
- package/dist/src/ops/proposal-reviews.js.map +1 -0
- package/dist/src/ops/relations.d.ts +57 -0
- package/dist/src/ops/relations.d.ts.map +1 -0
- package/dist/src/ops/relations.js +59 -0
- package/dist/src/ops/relations.js.map +1 -0
- package/dist/src/ops/types.d.ts +20 -0
- package/dist/src/ops/types.d.ts.map +1 -0
- package/dist/src/ops/types.js +20 -0
- package/dist/src/ops/types.js.map +1 -0
- package/dist/src/personal-space/constants.d.ts +1 -0
- package/dist/src/personal-space/constants.d.ts.map +1 -1
- package/dist/src/personal-space/constants.js +1 -0
- package/dist/src/personal-space/constants.js.map +1 -1
- package/dist/src/personal-space/create-space.d.ts +1 -18
- package/dist/src/personal-space/create-space.d.ts.map +1 -1
- package/dist/src/personal-space/create-space.js +1 -18
- package/dist/src/personal-space/create-space.js.map +1 -1
- package/dist/src/personal-space/has-space.d.ts +9 -2
- package/dist/src/personal-space/has-space.d.ts.map +1 -1
- package/dist/src/personal-space/has-space.js +9 -13
- package/dist/src/personal-space/has-space.js.map +1 -1
- package/dist/src/personal-space/has-space.test.d.ts +2 -0
- package/dist/src/personal-space/has-space.test.d.ts.map +1 -0
- package/dist/src/personal-space/has-space.test.js +30 -0
- package/dist/src/personal-space/has-space.test.js.map +1 -0
- package/dist/src/personal-space/publish-edit.d.ts +1 -22
- package/dist/src/personal-space/publish-edit.d.ts.map +1 -1
- package/dist/src/personal-space/publish-edit.js +10 -64
- package/dist/src/personal-space/publish-edit.js.map +1 -1
- package/dist/src/smart-wallet.d.ts +2 -4
- package/dist/src/smart-wallet.d.ts.map +1 -1
- package/dist/src/smart-wallet.js +6 -9
- package/dist/src/smart-wallet.js.map +1 -1
- package/dist/src/types.d.ts +25 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/package.json +14 -1
package/dist/src/ipfs.js
CHANGED
|
@@ -4,190 +4,47 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @since 0.1.1
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { gzipSync } from 'fflate';
|
|
10
|
-
import { imageSize } from 'image-size';
|
|
11
|
-
import { getApiOrigin } from './graph/constants.js';
|
|
12
|
-
import { assertValid, fromBytes, toGrcId } from './id-utils.js';
|
|
13
|
-
class IpfsUploadError extends Error {
|
|
14
|
-
_tag = 'IpfsUploadError';
|
|
15
|
-
}
|
|
7
|
+
import { publishEditCore, uploadCSVCore, uploadImageCore } from './ipfs-core.js';
|
|
8
|
+
import { resolveGeoNetwork } from './networks.js';
|
|
16
9
|
/**
|
|
17
10
|
* Generates correct GRC-20 v2 binary encoding for an Edit and uploads it to IPFS.
|
|
18
11
|
*
|
|
19
|
-
* @
|
|
20
|
-
*
|
|
21
|
-
* import { IPFS } from '@geoprotocol/geo-sdk';
|
|
22
|
-
*
|
|
23
|
-
* const { cid, editId } = await IPFS.publishEdit({
|
|
24
|
-
* name: 'Edit name',
|
|
25
|
-
* ops: ops,
|
|
26
|
-
* author: 'your-personal-space-id',
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @param args arguments for publishing an edit to IPFS {@link PublishEditProposalParams}
|
|
31
|
-
* @returns - {@link PublishEditResult}
|
|
12
|
+
* @deprecated Use `createGeoClient({ network }).personalSpaces.publishEdit(...)` or
|
|
13
|
+
* `createGeoClient({ network }).daoSpaces.proposeEdit(...)`.
|
|
32
14
|
*/
|
|
33
15
|
export async function publishEdit(args) {
|
|
34
|
-
const {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// Build the GRC-20 v2 Edit structure
|
|
42
|
-
const grcEdit = {
|
|
43
|
-
id: editId,
|
|
44
|
-
name,
|
|
45
|
-
authors: [toGrcId(author)],
|
|
46
|
-
createdAt: BigInt(Date.now()) * 1000n, // Convert to microseconds
|
|
47
|
-
ops,
|
|
48
|
-
};
|
|
49
|
-
// Encode to binary format
|
|
50
|
-
const binary = encodeEdit(grcEdit);
|
|
51
|
-
const MAX_EDIT_SIZE = 10 * 1024 * 1024; // 10MB
|
|
52
|
-
if (binary.byteLength > MAX_EDIT_SIZE) {
|
|
53
|
-
throw new Error(`Edit size (${(binary.byteLength / 1024 / 1024).toFixed(2)}MB) exceeds the ${MAX_EDIT_SIZE / 1024 / 1024}MB limit. Reduce the number of ops or split into multiple edits.`);
|
|
54
|
-
}
|
|
55
|
-
// Create a copy to ensure we have a regular ArrayBuffer for Blob compatibility
|
|
56
|
-
const binaryArray = new Uint8Array(binary);
|
|
57
|
-
const blob = new Blob([binaryArray], { type: 'application/octet-stream' });
|
|
58
|
-
const formData = new FormData();
|
|
59
|
-
formData.append('file', blob);
|
|
60
|
-
const cid = await Micro.runPromise(uploadBinary(formData, network));
|
|
61
|
-
// Convert the GrcId back to a grc-20-ts Id string
|
|
62
|
-
const editIdString = fromBytes(editId);
|
|
63
|
-
return { cid, editId: editIdString };
|
|
16
|
+
const { network = 'TESTNET', ...params } = args;
|
|
17
|
+
const config = resolveGeoNetwork(network);
|
|
18
|
+
return publishEditCore({
|
|
19
|
+
...params,
|
|
20
|
+
apiOrigin: config.apiOrigin,
|
|
21
|
+
fetch: globalThis.fetch,
|
|
22
|
+
});
|
|
64
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use `createGeoClient({ network }).storage.uploadImage(...)`.
|
|
26
|
+
*/
|
|
65
27
|
export async function uploadImage(params, network, alternativeGateway) {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const response = await fetch(params.url);
|
|
74
|
-
blob = await response.blob();
|
|
75
|
-
}
|
|
76
|
-
formData.append('file', blob);
|
|
77
|
-
const buffer = new Uint8Array(await blob.arrayBuffer());
|
|
78
|
-
let dimensions;
|
|
79
|
-
try {
|
|
80
|
-
dimensions = imageSize(buffer);
|
|
81
|
-
}
|
|
82
|
-
catch (_error) { }
|
|
83
|
-
const cid = await Micro.runPromise(uploadFile(formData, network, alternativeGateway));
|
|
84
|
-
if (dimensions) {
|
|
85
|
-
return {
|
|
86
|
-
cid,
|
|
87
|
-
dimensions: {
|
|
88
|
-
width: dimensions.width,
|
|
89
|
-
height: dimensions.height,
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
cid,
|
|
95
|
-
};
|
|
28
|
+
const config = resolveGeoNetwork(network);
|
|
29
|
+
return uploadImageCore({
|
|
30
|
+
...params,
|
|
31
|
+
apiOrigin: config.apiOrigin,
|
|
32
|
+
fetch: globalThis.fetch,
|
|
33
|
+
alternativeGateway,
|
|
34
|
+
});
|
|
96
35
|
}
|
|
97
36
|
/**
|
|
98
37
|
* Uploads a CSV file to IPFS and returns the CID. This CSV
|
|
99
38
|
* file will be compressed using gzip before being uploaded.
|
|
100
39
|
*
|
|
101
|
-
* @
|
|
102
|
-
* ```ts
|
|
103
|
-
* const file = Bun.file('cities.csv');
|
|
104
|
-
* const fileText = await file.text();
|
|
105
|
-
*
|
|
106
|
-
* const cid = await Ipfs.uploadCSV(fileText);
|
|
107
|
-
* ```
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* import { Csv } from '@geoprotocol/geo-sdk';
|
|
112
|
-
*
|
|
113
|
-
* const csvString = Csv.stringify({
|
|
114
|
-
* data: Array.from({ length: 151_000 }, (_, i: number) => [i.toString(), (i * 2).toString(), (i * 3).toString()]),
|
|
115
|
-
* metadata: {
|
|
116
|
-
* filetype: 'CSV',
|
|
117
|
-
* columns: [
|
|
118
|
-
* {
|
|
119
|
-
* id: 'foo',
|
|
120
|
-
* type: 'TEXT',
|
|
121
|
-
* },
|
|
122
|
-
* {
|
|
123
|
-
* id: 'bar',
|
|
124
|
-
* type: 'NUMBER',
|
|
125
|
-
* },
|
|
126
|
-
* {
|
|
127
|
-
* id: 'baz',
|
|
128
|
-
* type: 'TEXT',
|
|
129
|
-
* },
|
|
130
|
-
* ],
|
|
131
|
-
* },
|
|
132
|
-
* })
|
|
133
|
-
*
|
|
134
|
-
* const cid = await Ipfs.uploadCSV(csvString);
|
|
135
|
-
* ```
|
|
136
|
-
*
|
|
137
|
-
* @param csvString The CSV to upload as a string
|
|
138
|
-
* @returns IPFS CID representing the uploaded file prefixed with `ipfs://`
|
|
40
|
+
* @deprecated Use `createGeoClient({ network }).storage.uploadCSV(...)`.
|
|
139
41
|
*/
|
|
140
42
|
export async function uploadCSV(csvString, network) {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
formData.append('file', new Blob([blob], { type: 'text/csv' }));
|
|
147
|
-
return await Micro.runPromise(uploadBinary(formData, network));
|
|
148
|
-
}
|
|
149
|
-
function uploadBinary(formData, network = 'TESTNET') {
|
|
150
|
-
return Micro.gen(function* () {
|
|
151
|
-
const result = yield* Micro.tryPromise({
|
|
152
|
-
try: () => fetch(`${getApiOrigin(network)}/ipfs/upload-edit`, {
|
|
153
|
-
method: 'POST',
|
|
154
|
-
body: formData,
|
|
155
|
-
}),
|
|
156
|
-
catch: error => new IpfsUploadError(`Could not upload data to IPFS: ${error}`),
|
|
157
|
-
});
|
|
158
|
-
const maybeCid = yield* Micro.tryPromise({
|
|
159
|
-
try: async () => {
|
|
160
|
-
const { cid } = await result.json();
|
|
161
|
-
return cid;
|
|
162
|
-
},
|
|
163
|
-
catch: error => new IpfsUploadError(`Could not parse response from IPFS: ${error}`),
|
|
164
|
-
});
|
|
165
|
-
return maybeCid;
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
function uploadFile(formData, network = 'TESTNET', alternativeGateway) {
|
|
169
|
-
return Micro.gen(function* () {
|
|
170
|
-
let apiUrl = `${getApiOrigin(network)}/ipfs/upload-file`;
|
|
171
|
-
if (alternativeGateway) {
|
|
172
|
-
apiUrl = `${getApiOrigin('TESTNET')}/ipfs/upload-file-alternative-gateway`;
|
|
173
|
-
}
|
|
174
|
-
const result = yield* Micro.tryPromise({
|
|
175
|
-
try: () => fetch(apiUrl, {
|
|
176
|
-
method: 'POST',
|
|
177
|
-
body: formData,
|
|
178
|
-
}),
|
|
179
|
-
catch: error => {
|
|
180
|
-
return new IpfsUploadError(`Could not upload file to IPFS: ${error}`);
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
const maybeCid = yield* Micro.tryPromise({
|
|
184
|
-
try: async () => {
|
|
185
|
-
const { cid } = await result.json();
|
|
186
|
-
return cid;
|
|
187
|
-
},
|
|
188
|
-
catch: error => new IpfsUploadError(`Could not parse response from IPFS: ${error}`),
|
|
189
|
-
});
|
|
190
|
-
return maybeCid;
|
|
43
|
+
const config = resolveGeoNetwork(network);
|
|
44
|
+
return uploadCSVCore({
|
|
45
|
+
csvString,
|
|
46
|
+
apiOrigin: config.apiOrigin,
|
|
47
|
+
fetch: globalThis.fetch,
|
|
191
48
|
});
|
|
192
49
|
}
|
|
193
50
|
//# sourceMappingURL=ipfs.js.map
|
package/dist/src/ipfs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipfs.js","sourceRoot":"","sources":["../../src/ipfs.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"ipfs.js","sourceRoot":"","sources":["../../src/ipfs.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAkBlD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,IAA+B;IAC/D,MAAM,EAAE,OAAO,GAAG,SAAS,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;IAChD,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,eAAe,CAAC;QACrB,GAAG,MAAM;QACT,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,KAAK,EAAE,UAAU,CAAC,KAAK;KACxB,CAAC,CAAC;AACL,CAAC;AAUD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAA0B,EAAE,OAAiB,EAAE,kBAA4B;IAC3G,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,eAAe,CAAC;QACrB,GAAG,MAAM;QACT,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,kBAAkB;KACnB,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,SAAiB,EAAE,OAAiB;IAClE,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,aAAa,CAAC;QACnB,SAAS;QACT,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,KAAK,EAAE,UAAU,CAAC,KAAK;KACxB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { GeoContractAddresses, GeoNetworkConfig, Networkish } from './types.js';
|
|
2
|
+
export declare const TESTNET_API_ORIGIN = "https://testnet-api.geobrowser.io";
|
|
3
|
+
/**
|
|
4
|
+
* Defines a Geo network configuration for `createGeoClient`.
|
|
5
|
+
*
|
|
6
|
+
* Use this for local contract deployments, private testnets, or any environment
|
|
7
|
+
* that is not covered by the built-in `GeoTestnetConfig`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createGeoClient, defineGeoNetworkConfig } from '@geoprotocol/geo-sdk';
|
|
12
|
+
*
|
|
13
|
+
* const localGeo = defineGeoNetworkConfig({
|
|
14
|
+
* id: 'LOCAL',
|
|
15
|
+
* name: 'Local Geo',
|
|
16
|
+
* apiOrigin: 'http://localhost:3000',
|
|
17
|
+
* chain: {
|
|
18
|
+
* id: 31337,
|
|
19
|
+
* name: 'Anvil',
|
|
20
|
+
* rpcUrl: 'http://localhost:8545',
|
|
21
|
+
* },
|
|
22
|
+
* contracts: {
|
|
23
|
+
* SPACE_REGISTRY_ADDRESS: '0x0000000000000000000000000000000000000000',
|
|
24
|
+
* DAO_SPACE_FACTORY_ADDRESS: '0x0000000000000000000000000000000000000000',
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const geo = createGeoClient({ network: localGeo });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function defineGeoNetworkConfig(config: GeoNetworkConfig): GeoNetworkConfig;
|
|
32
|
+
/**
|
|
33
|
+
* Built-in Geo testnet configuration.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { createGeoClient, GeoTestnetConfig } from '@geoprotocol/geo-sdk';
|
|
38
|
+
*
|
|
39
|
+
* const geo = createGeoClient({ network: GeoTestnetConfig });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const GeoTestnetConfig: GeoNetworkConfig;
|
|
43
|
+
export declare function resolveGeoNetwork(network?: Networkish): GeoNetworkConfig;
|
|
44
|
+
export declare function requireGeoContract(network: GeoNetworkConfig, name: keyof GeoContractAddresses): `0x${string}`;
|
|
45
|
+
export declare function getApiOrigin(network?: Networkish): string;
|
|
46
|
+
//# sourceMappingURL=networks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../../src/networks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAErF,eAAO,MAAM,kBAAkB,sCAAsC,CAAC;AAQtE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAejF;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,kBAU3B,CAAC;AAEH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,UAAsB,GAAG,gBAAgB,CASnF;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,oBAAoB,GAAG,KAAK,MAAM,EAAE,CAO7G;AAED,wBAAgB,YAAY,CAAC,OAAO,GAAE,UAAsB,GAAG,MAAM,CAEpE"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { TESTNET } from '../contracts.js';
|
|
2
|
+
export const TESTNET_API_ORIGIN = 'https://testnet-api.geobrowser.io';
|
|
3
|
+
const GEO_TESTNET_RPC_URL = 'https://rpc-geo-test-zc16z3tcvf.t.conduit.xyz';
|
|
4
|
+
function asContractAddresses(contracts) {
|
|
5
|
+
return contracts;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Defines a Geo network configuration for `createGeoClient`.
|
|
9
|
+
*
|
|
10
|
+
* Use this for local contract deployments, private testnets, or any environment
|
|
11
|
+
* that is not covered by the built-in `GeoTestnetConfig`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { createGeoClient, defineGeoNetworkConfig } from '@geoprotocol/geo-sdk';
|
|
16
|
+
*
|
|
17
|
+
* const localGeo = defineGeoNetworkConfig({
|
|
18
|
+
* id: 'LOCAL',
|
|
19
|
+
* name: 'Local Geo',
|
|
20
|
+
* apiOrigin: 'http://localhost:3000',
|
|
21
|
+
* chain: {
|
|
22
|
+
* id: 31337,
|
|
23
|
+
* name: 'Anvil',
|
|
24
|
+
* rpcUrl: 'http://localhost:8545',
|
|
25
|
+
* },
|
|
26
|
+
* contracts: {
|
|
27
|
+
* SPACE_REGISTRY_ADDRESS: '0x0000000000000000000000000000000000000000',
|
|
28
|
+
* DAO_SPACE_FACTORY_ADDRESS: '0x0000000000000000000000000000000000000000',
|
|
29
|
+
* },
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* const geo = createGeoClient({ network: localGeo });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function defineGeoNetworkConfig(config) {
|
|
36
|
+
if (!config.id) {
|
|
37
|
+
throw new Error('Geo network config requires an `id`');
|
|
38
|
+
}
|
|
39
|
+
if (!config.name) {
|
|
40
|
+
throw new Error('Geo network config requires a `name`');
|
|
41
|
+
}
|
|
42
|
+
if (!config.apiOrigin) {
|
|
43
|
+
throw new Error('Geo network config requires an `apiOrigin`');
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
...config,
|
|
47
|
+
contracts: config.contracts ?? {},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Built-in Geo testnet configuration.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { createGeoClient, GeoTestnetConfig } from '@geoprotocol/geo-sdk';
|
|
56
|
+
*
|
|
57
|
+
* const geo = createGeoClient({ network: GeoTestnetConfig });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export const GeoTestnetConfig = defineGeoNetworkConfig({
|
|
61
|
+
id: 'TESTNET',
|
|
62
|
+
name: 'Geo Testnet',
|
|
63
|
+
apiOrigin: TESTNET_API_ORIGIN,
|
|
64
|
+
chain: {
|
|
65
|
+
id: 19411,
|
|
66
|
+
name: 'Geo Testnet',
|
|
67
|
+
rpcUrl: GEO_TESTNET_RPC_URL,
|
|
68
|
+
},
|
|
69
|
+
contracts: asContractAddresses(TESTNET),
|
|
70
|
+
});
|
|
71
|
+
export function resolveGeoNetwork(network = 'TESTNET') {
|
|
72
|
+
if (network === 'TESTNET') {
|
|
73
|
+
return GeoTestnetConfig;
|
|
74
|
+
}
|
|
75
|
+
if (typeof network === 'string') {
|
|
76
|
+
throw new Error(`Unknown Geo network "${network}". Use GeoTestnetConfig or defineGeoNetworkConfig().`);
|
|
77
|
+
}
|
|
78
|
+
return defineGeoNetworkConfig(network);
|
|
79
|
+
}
|
|
80
|
+
export function requireGeoContract(network, name) {
|
|
81
|
+
const address = network.contracts?.[name];
|
|
82
|
+
if (!address) {
|
|
83
|
+
throw new Error(`Geo network "${network.name}" is missing required contract address ${name}`);
|
|
84
|
+
}
|
|
85
|
+
return address;
|
|
86
|
+
}
|
|
87
|
+
export function getApiOrigin(network = 'TESTNET') {
|
|
88
|
+
return resolveGeoNetwork(network).apiOrigin;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=networks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.js","sourceRoot":"","sources":["../../src/networks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,mCAAmC,CAAC;AAEtE,MAAM,mBAAmB,GAAG,+CAA+C,CAAC;AAE5E,SAAS,mBAAmB,CAAC,SAA6C;IACxE,OAAO,SAAiC,CAAC;AAC3C,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAwB;IAC7D,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;IAED,OAAO;QACL,GAAG,MAAM;QACT,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE;KAClC,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;IACrD,EAAE,EAAE,SAAS;IACb,IAAI,EAAE,aAAa;IACnB,SAAS,EAAE,kBAAkB;IAC7B,KAAK,EAAE;QACL,EAAE,EAAE,KAAK;QACT,IAAI,EAAE,aAAa;QACnB,MAAM,EAAE,mBAAmB;KAC5B;IACD,SAAS,EAAE,mBAAmB,CAAC,OAAO,CAAC;CACxC,CAAC,CAAC;AAEH,MAAM,UAAU,iBAAiB,CAAC,UAAsB,SAAS;IAC/D,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IACD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,sDAAsD,CAAC,CAAC;IACzG,CAAC;IAED,OAAO,sBAAsB,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAyB,EAAE,IAAgC;IAC5F,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,gBAAgB,OAAO,CAAC,IAAI,0CAA0C,IAAI,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,UAAsB,SAAS;IAC1D,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Id as IdType } from '../id.js';
|
|
2
|
+
import type { CreateResult, UpdateCommentParams } from '../types.js';
|
|
3
|
+
export type ReplyToContext = {
|
|
4
|
+
/** Ancestor entity ID from an existing reply-to relation. */
|
|
5
|
+
entityId: string;
|
|
6
|
+
/** Space ID associated with the ancestor reply target. */
|
|
7
|
+
spaceId: string;
|
|
8
|
+
/** Existing reply-to relation position used for parent-to-root ordering. */
|
|
9
|
+
position: string | null;
|
|
10
|
+
};
|
|
11
|
+
export type CreateCommentOpsParams = {
|
|
12
|
+
id?: IdType | string;
|
|
13
|
+
content: string;
|
|
14
|
+
replyTo: {
|
|
15
|
+
entityId: IdType | string;
|
|
16
|
+
spaceId: IdType | string;
|
|
17
|
+
};
|
|
18
|
+
resolved?: boolean;
|
|
19
|
+
replyToRelations?: ReplyToContext[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Builds create-comment ops.
|
|
23
|
+
*
|
|
24
|
+
* The direct `replyTo` target is always included. If `replyToRelations` are
|
|
25
|
+
* provided, they are sorted by position and appended after the direct parent so
|
|
26
|
+
* nested comments preserve a parent-to-root reply chain.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* Create a comment on an entity.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { comments } from '@geoprotocol/geo-sdk/ops';
|
|
33
|
+
*
|
|
34
|
+
* const { id, ops } = comments.create({
|
|
35
|
+
* content: 'Looks good to me',
|
|
36
|
+
* replyTo: { entityId, spaceId },
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* Create a nested comment when reply context is already available.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* const { ops } = comments.create({
|
|
45
|
+
* content: 'Replying to the parent comment',
|
|
46
|
+
* replyTo: { entityId: parentCommentId, spaceId },
|
|
47
|
+
* replyToRelations: [
|
|
48
|
+
* { entityId: rootEntityId, spaceId, position: 'a0' },
|
|
49
|
+
* ],
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param params Comment content, reply target, optional ID, resolved state, and optional ancestor reply context.
|
|
54
|
+
* @returns Comment entity ID and create ops.
|
|
55
|
+
* @throws When the comment ID or reply target IDs are invalid.
|
|
56
|
+
*/
|
|
57
|
+
export declare const create: ({ id: providedId, content, replyTo, resolved, replyToRelations, }: CreateCommentOpsParams) => CreateResult;
|
|
58
|
+
/**
|
|
59
|
+
* Builds update-comment ops.
|
|
60
|
+
*
|
|
61
|
+
* If `content` is supplied, both markdown content and the derived comment name
|
|
62
|
+
* are updated. If `resolved` is supplied, the resolved property is updated.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { comments } from '@geoprotocol/geo-sdk/ops';
|
|
67
|
+
*
|
|
68
|
+
* const { ops } = comments.update({
|
|
69
|
+
* id: commentId,
|
|
70
|
+
* content: 'Updated comment text',
|
|
71
|
+
* resolved: true,
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @param params Comment ID plus content and/or resolved state to update.
|
|
76
|
+
* @returns Comment entity ID and update ops.
|
|
77
|
+
* @throws When the comment ID is invalid.
|
|
78
|
+
*/
|
|
79
|
+
export declare const update: ({ id, content, resolved }: UpdateCommentParams) => CreateResult;
|
|
80
|
+
//# sourceMappingURL=comments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../../src/ops/comments.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,KAAK,EAAE,YAAY,EAAmB,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGtF,MAAM,MAAM,cAAc,GAAG;IAC3B,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE;QACP,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;QAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;KAC1B,CAAC;IACF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gBAAgB,CAAC,EAAE,cAAc,EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,MAAM,GAAI,mEAMpB,sBAAsB,KAAG,YAqD3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,MAAM,GAAI,2BAA2B,mBAAmB,KAAG,YA0BvE,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { COMMENT_TYPE } from '../core/ids/content.js';
|
|
2
|
+
import { MARKDOWN_CONTENT, REPLY_TO_PROPERTY, RESOLVED_PROPERTY } from '../core/ids/system.js';
|
|
3
|
+
import { generateBetween } from '../core/position.js';
|
|
4
|
+
import { deriveCommentName } from '../graph/comment-utils.js';
|
|
5
|
+
import { Id } from '../id.js';
|
|
6
|
+
import { assertValid, generate } from '../id-utils.js';
|
|
7
|
+
import { create as createEntity, update as updateEntity } from './entities.js';
|
|
8
|
+
/**
|
|
9
|
+
* Builds create-comment ops.
|
|
10
|
+
*
|
|
11
|
+
* The direct `replyTo` target is always included. If `replyToRelations` are
|
|
12
|
+
* provided, they are sorted by position and appended after the direct parent so
|
|
13
|
+
* nested comments preserve a parent-to-root reply chain.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* Create a comment on an entity.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { comments } from '@geoprotocol/geo-sdk/ops';
|
|
20
|
+
*
|
|
21
|
+
* const { id, ops } = comments.create({
|
|
22
|
+
* content: 'Looks good to me',
|
|
23
|
+
* replyTo: { entityId, spaceId },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* Create a nested comment when reply context is already available.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* const { ops } = comments.create({
|
|
32
|
+
* content: 'Replying to the parent comment',
|
|
33
|
+
* replyTo: { entityId: parentCommentId, spaceId },
|
|
34
|
+
* replyToRelations: [
|
|
35
|
+
* { entityId: rootEntityId, spaceId, position: 'a0' },
|
|
36
|
+
* ],
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param params Comment content, reply target, optional ID, resolved state, and optional ancestor reply context.
|
|
41
|
+
* @returns Comment entity ID and create ops.
|
|
42
|
+
* @throws When the comment ID or reply target IDs are invalid.
|
|
43
|
+
*/
|
|
44
|
+
export const create = ({ id: providedId, content, replyTo, resolved = false, replyToRelations = [], }) => {
|
|
45
|
+
if (providedId)
|
|
46
|
+
assertValid(providedId, '`id` in `Ops.comments.create`');
|
|
47
|
+
assertValid(replyTo.entityId, '`replyTo.entityId` in `Ops.comments.create`');
|
|
48
|
+
assertValid(replyTo.spaceId, '`replyTo.spaceId` in `Ops.comments.create`');
|
|
49
|
+
const id = providedId ?? generate();
|
|
50
|
+
const orderedTargets = [];
|
|
51
|
+
if (replyToRelations.length > 0) {
|
|
52
|
+
orderedTargets.push({ toEntity: replyTo.entityId, toSpace: replyTo.spaceId });
|
|
53
|
+
const sorted = [...replyToRelations].sort((a, b) => {
|
|
54
|
+
if (a.position === null && b.position === null)
|
|
55
|
+
return 0;
|
|
56
|
+
if (a.position === null)
|
|
57
|
+
return 1;
|
|
58
|
+
if (b.position === null)
|
|
59
|
+
return -1;
|
|
60
|
+
return a.position.localeCompare(b.position);
|
|
61
|
+
});
|
|
62
|
+
for (const relation of sorted) {
|
|
63
|
+
orderedTargets.push({ toEntity: relation.entityId, toSpace: relation.spaceId });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
orderedTargets.push({ toEntity: replyTo.entityId, toSpace: replyTo.spaceId });
|
|
68
|
+
}
|
|
69
|
+
let lastPosition = null;
|
|
70
|
+
const replyToRelationEntries = [];
|
|
71
|
+
for (const target of orderedTargets) {
|
|
72
|
+
const position = generateBetween(lastPosition, null);
|
|
73
|
+
replyToRelationEntries.push({ ...target, position });
|
|
74
|
+
lastPosition = position;
|
|
75
|
+
}
|
|
76
|
+
const result = createEntity({
|
|
77
|
+
id,
|
|
78
|
+
name: deriveCommentName(content),
|
|
79
|
+
types: [COMMENT_TYPE],
|
|
80
|
+
values: [
|
|
81
|
+
{
|
|
82
|
+
property: MARKDOWN_CONTENT,
|
|
83
|
+
type: 'text',
|
|
84
|
+
value: content,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
property: RESOLVED_PROPERTY,
|
|
88
|
+
type: 'boolean',
|
|
89
|
+
value: resolved,
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
relations: {
|
|
93
|
+
[REPLY_TO_PROPERTY]: replyToRelationEntries,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
return { id: Id(id), ops: result.ops };
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Builds update-comment ops.
|
|
100
|
+
*
|
|
101
|
+
* If `content` is supplied, both markdown content and the derived comment name
|
|
102
|
+
* are updated. If `resolved` is supplied, the resolved property is updated.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* import { comments } from '@geoprotocol/geo-sdk/ops';
|
|
107
|
+
*
|
|
108
|
+
* const { ops } = comments.update({
|
|
109
|
+
* id: commentId,
|
|
110
|
+
* content: 'Updated comment text',
|
|
111
|
+
* resolved: true,
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @param params Comment ID plus content and/or resolved state to update.
|
|
116
|
+
* @returns Comment entity ID and update ops.
|
|
117
|
+
* @throws When the comment ID is invalid.
|
|
118
|
+
*/
|
|
119
|
+
export const update = ({ id, content, resolved }) => {
|
|
120
|
+
assertValid(id, '`id` in `Ops.comments.update`');
|
|
121
|
+
const values = [];
|
|
122
|
+
if (content !== undefined) {
|
|
123
|
+
values.push({
|
|
124
|
+
property: MARKDOWN_CONTENT,
|
|
125
|
+
type: 'text',
|
|
126
|
+
value: content,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (resolved !== undefined) {
|
|
130
|
+
values.push({
|
|
131
|
+
property: RESOLVED_PROPERTY,
|
|
132
|
+
type: 'boolean',
|
|
133
|
+
value: resolved,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return updateEntity({
|
|
137
|
+
id,
|
|
138
|
+
name: content !== undefined ? deriveCommentName(content) : undefined,
|
|
139
|
+
values,
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
//# sourceMappingURL=comments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comments.js","sourceRoot":"","sources":["../../../src/ops/comments.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CreateResult, EntityParams, UpdateEntityParams } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Builds create-entity ops.
|
|
4
|
+
*
|
|
5
|
+
* This is the pure version of entity creation. It validates supplied IDs and
|
|
6
|
+
* encodes the same operation shape as the legacy `createEntity(...)` helper.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { entities } from '@geoprotocol/geo-sdk/ops';
|
|
11
|
+
*
|
|
12
|
+
* const { id, ops } = entities.create({
|
|
13
|
+
* name: 'Restaurant',
|
|
14
|
+
* description: 'A neighborhood restaurant',
|
|
15
|
+
* types: [restaurantTypeId],
|
|
16
|
+
* values: [
|
|
17
|
+
* {
|
|
18
|
+
* property: websitePropertyId,
|
|
19
|
+
* type: 'text',
|
|
20
|
+
* value: 'https://example.com',
|
|
21
|
+
* },
|
|
22
|
+
* ],
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param params Entity fields, values, relations, and types to encode.
|
|
27
|
+
* @returns Generated or supplied entity ID and create ops.
|
|
28
|
+
* @throws When any supplied ID is invalid.
|
|
29
|
+
*/
|
|
30
|
+
export declare const create: (params: EntityParams) => CreateResult;
|
|
31
|
+
/**
|
|
32
|
+
* Builds update-entity ops.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { entities } from '@geoprotocol/geo-sdk/ops';
|
|
37
|
+
*
|
|
38
|
+
* const { ops } = entities.update({
|
|
39
|
+
* id: entityId,
|
|
40
|
+
* name: 'Updated restaurant name',
|
|
41
|
+
* unset: [{ property: oldDescriptionPropertyId }],
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @param params Entity ID and values/properties to update or unset.
|
|
46
|
+
* @returns Entity ID and update ops.
|
|
47
|
+
* @throws When any supplied ID is invalid.
|
|
48
|
+
*/
|
|
49
|
+
export declare const update: (params: UpdateEntityParams) => CreateResult;
|
|
50
|
+
//# sourceMappingURL=entities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../../src/ops/entities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAElF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,MAAM,GAAI,QAAQ,YAAY,KAAG,YAAoC,CAAC;AAEnF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,MAAM,GAAI,QAAQ,kBAAkB,KAAG,YAAoC,CAAC"}
|