change of type export

This commit is contained in:
Marcel Lorbeer 2024-05-10 12:06:15 +02:00
parent 5f3deb438e
commit 881f4fe1b1
5 changed files with 17 additions and 23 deletions

View File

@ -52,7 +52,7 @@ return {
self._checkInstallation = function() self._checkInstallation = function()
if not self then error("Please Setup MarcSync before using MarcSync.") end if not self then error("Please Setup MarcSync before using MarcSync.") end
if not self._accessToken then error("[MarcSync] Please set a Token before using MarcSync.") end if not self._accessToken then error("[MarcSync] Please set a Token before using MarcSync.") end
if not HttpService.HttpEnabled then error("Please Enable HTTPService in order to use MarcSync.") end if not game:GetService("HttpService").HttpEnabled then error("Please Enable HTTPService in order to use MarcSync.") end
end end
self = setmetatable(self, { self = setmetatable(self, {

View File

@ -1,13 +1,11 @@
local Utils = require(script.Parent.Parent.Utils) local Utils = require(script.Parent.Parent.Utils)
local Entry = require(script.Parent.Entry) local Entry = require(script.Parent.Entry)
local types = { local Types = require(script.Parent.Parent.Types)
EntryData = require(script.Parent.Parent.Types.EntryData).getType()
}
local Collection = {} local Collection = {}
Collection.createEntry = function(self:typeof(Collection), data:typeof(types.EntryData)):typeof(Entry.new()) Collection.createEntry = function(self:typeof(Collection), data:Types.EntryData):typeof(Entry.new())
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end
local result = Utils.makeHTTPRequest("entry", "POST", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["data"]=data}, self._accessToken); local result = Utils.makeHTTPRequest("entry", "POST", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["data"]=data}, self._accessToken);
@ -21,7 +19,7 @@ Collection.createEntry = function(self:typeof(Collection), data:typeof(types.Ent
return result return result
end end
Collection.updateEntries = function(self:typeof(Collection), filters:typeof(types.EntryData), data:typeof(types.EntryData)):number Collection.updateEntries = function(self:typeof(Collection), filters:Types.EntryData, data:Types.EntryData):number
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end
local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters,["data"]=data}, self._accessToken); local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters,["data"]=data}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end if not result["success"] then error(result["errorMessage"]) end
@ -29,7 +27,7 @@ Collection.updateEntries = function(self:typeof(Collection), filters:typeof(type
return result["modifiedEntries"] return result["modifiedEntries"]
end end
Collection.getEntries = function(self:typeof(Collection), filters:typeof(types.EntryData)):{[number]:typeof(Entry.new())} Collection.getEntries = function(self:typeof(Collection), filters:Types.EntryData):{[number]:typeof(Entry.new())}
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end
if not filters then filters = {} end if not filters then filters = {} end
local result = Utils.makeHTTPRequest("entry", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName.."?isQuery=true", {["filters"]=filters}, self._accessToken); local result = Utils.makeHTTPRequest("entry", "DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName.."?isQuery=true", {["filters"]=filters}, self._accessToken);
@ -46,7 +44,7 @@ Collection.getEntries = function(self:typeof(Collection), filters:typeof(types.E
return result return result
end end
Collection.deleteEntries = function(self:typeof(Collection), filters:typeof(types.EntryData)):number Collection.deleteEntries = function(self:typeof(Collection), filters:Types.EntryData):number
if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end if not self._collectionName then error("[MarcSync: Collection] Invalid Object created or trying to access an destroied object.") end
local result = Utils.makeHTTPRequest("DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters}, self._accessToken); local result = Utils.makeHTTPRequest("DELETE", "https://api.marcsync.dev/v0/entries/"..self._collectionName, {["filters"]=filters}, self._accessToken);
if not result["success"] then error(result["errorMessage"]) end if not result["success"] then error(result["errorMessage"]) end

View File

@ -1,8 +1,6 @@
local Utils = require(script.Parent.Parent.Utils) local Utils = require(script.Parent.Parent.Utils)
local types = { local Types = require(script.Parent.Parent.Types)
EntryData = require(script.Parent.Parent.Types.EntryData).getType()
}
local Entry = {} local Entry = {}
@ -11,11 +9,11 @@ Entry.getValue = function(self:typeof(Entry), key:string):any
return self._entryData[key] return self._entryData[key]
end end
Entry.getValues = function(self:typeof(Entry)):typeof(types.EntryData) Entry.getValues = function(self:typeof(Entry)):Types.EntryData
return self._entryData return self._entryData
end end
Entry.updateValues = function(self:typeof(Entry), data:typeof(types.EntryData)):number Entry.updateValues = function(self:typeof(Entry), data:Types.EntryData):number
local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId},["data"]=data}, self._accessToken); local result = Utils.makeHTTPRequest("entry", "PUT", "https://api.marcsync.dev/v0/entries/"..self._tableId, {["filters"]={["_id"]=self._objectId},["data"]=data}, self._accessToken);
if result["success"] and result["modifiedEntries"] and result["modifiedEntries"] > 0 then if result["success"] and result["modifiedEntries"] and result["modifiedEntries"] > 0 then
@ -39,7 +37,7 @@ Entry.delete = function(self:typeof(Entry))
end end
return { return {
new = function(tableId:string, entryData:typeof(types.EntryData), accessToken:string):typeof(Entry) new = function(tableId:string, entryData:Types.EntryData, accessToken:string):typeof(Entry)
if not tableId or not entryData or not entryData["_id"] or not accessToken then error("[MarcSync: Entry] Tried creating invalid Entry Object.") end if not tableId or not entryData or not entryData["_id"] or not accessToken then error("[MarcSync: Entry] Tried creating invalid Entry Object.") end
local self = {} local self = {}
self._tableId = tableId self._tableId = tableId

7
src/MarcSync/Types.lua Normal file
View File

@ -0,0 +1,7 @@
local types = {}
export type EntryData = {
[string]: any
}
return types

View File

@ -1,9 +0,0 @@
type EntryData = {
[string]: any
}
return {
getType = function(): EntryData
return {}
end,
}